From 9af18fa20fe7a2d6633d62ac04d737e1acb9245c Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 3 Oct 2008 16:38:39 -0700 Subject: [PATCH] Added a basic test case. So far it can be used to make sure your stylesheets compile. Eventually it should provide assertions for generated rules and styles. --- lib/compass/test_case.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/compass/test_case.rb diff --git a/lib/compass/test_case.rb b/lib/compass/test_case.rb new file mode 100644 index 00000000..050ea35f --- /dev/null +++ b/lib/compass/test_case.rb @@ -0,0 +1,37 @@ +module Compass + # Write your unit test like this if you want to make sure all your stylesheets compile. + # + # require 'compass/test_case' + # class StylesheetsTest < Compass::TestCase + # def test_stylesheets + # my_sass_files.each do |sass_file| + # assert_compiles(sass_file) do |result| + # assert_not_blank result + # end + # end + # end + # protected + # def my_sass_files + # Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "../..", "app/stylesheets/**/[^_]*.sass"))) + # end + # end + class TestCase < Test::Unit::TestCase + def setup + @last_compile = nil + end + + def compile(stylesheet) + input = open(stylesheet) + template = input.read() + input.close() + @last_compile = ::Sass::Engine.new(template, + ::Sass::Plugin.engine_options(:style => :compact, :filename => stylesheet)).render + yield @last_compile if block_given? + end + + def assert_compiles(stylesheet, &block) + compile(stylesheet, &block) + end + + end +end