From 5f18e1d0fc5f4c28d5fd473424660edf2dead8a6 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sat, 23 Jan 2010 17:01:19 -0800 Subject: [PATCH] [Sass] Add a bunch more callback tests. --- lib/sass/plugin.rb | 6 ++++-- test/sass/plugin_test.rb | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index f2fa494c..aaf7e8b6 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -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] diff --git a/test/sass/plugin_test.rb b/test/sass/plugin_test.rb index 2166b8d1..5cc1b346 100755 --- a/test/sass/plugin_test.rb +++ b/test/sass/plugin_test.rb @@ -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?