1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Add a bunch more callback tests.

This commit is contained in:
Nathan Weizenbaum 2010-01-23 17:01:19 -08:00
parent 81f885342f
commit 5f18e1d0fc
2 changed files with 38 additions and 4 deletions

View file

@ -103,9 +103,11 @@ module Sass
# into which to put CSS files.
#
# Note that even if multiple levels of directories need to be created,
# the callback will only be run once.
# the callback may only be run once.
# For example, if "foo/" exists and "foo/bar/baz/" needs to be created,
# this will only be run for "foo/bar/baz/".
# this may only be run for "foo/bar/baz/".
# This is not a guarantee, however;
# it may also be run for "foo/bar/".
#
# @yield [dirname]
# @yieldparam dirname [String]

View file

@ -193,6 +193,36 @@ CSS
assert_no_callback :not_updating_stylesheet, template_loc("_partial"), tempfile_loc("_partial")
end
def test_not_updating_stylesheet_callback_for_error
Sass::Plugin.options[:always_update] = false
touch 'bork1'
assert_no_callback :not_updating_stylesheet, template_loc("bork1"), tempfile_loc("bork1")
end
def test_compilation_error_callback
Sass::Plugin.options[:always_update] = false
touch 'bork1'
assert_callback(:compilation_error,
lambda {|e| e.message == 'Undefined variable: "!bork".'},
template_loc("bork1"), tempfile_loc("bork1"))
end
def test_compilation_error_callback_for_file_access
Sass::Plugin.options[:always_update] = false
assert_callback(:compilation_error,
lambda {|e| e.is_a?(Errno::ENOENT)},
template_loc("nonexistent"), tempfile_loc("nonexistent")) do
Sass::Plugin.update_stylesheets([[template_loc("nonexistent"), tempfile_loc("nonexistent")]])
end
end
def test_creating_directory_callback
Sass::Plugin.options[:always_update] = false
dir = File.join(tempfile_loc, "subdir", "nested_subdir")
FileUtils.rm_r dir
assert_callback :creating_directory, dir
end
## Regression
def test_cached_dependencies_update
@ -243,8 +273,10 @@ CSS
def assert_callback(name, *expected_args)
run = false
Sass::Plugin.send("on_#{name}") do |*a|
run = true if expected_args == a
Sass::Plugin.send("on_#{name}") do |*args|
run ||= expected_args.zip(args).all? do |ea, a|
ea.respond_to?(:call) ? ea.call(a) : ea == a
end
end
if block_given?