Permalink
Browse files

rewrite specs using shoulda and clean generation

  • Loading branch information...
1 parent 231257a commit d2580e243555652972317073a9cb19c523816294 @grosser grosser committed Feb 13, 2010
@@ -1,2 +0,0 @@
-@text_light: #ffffff;
-@text_dark: #222222;
@@ -1,2 +0,0 @@
-/* This file should not be parsed through LESS */
-div { width: 1 + 1 }
@@ -1,3 +0,0 @@
-.allforms {
- font-size: 110%;
-}
@@ -1 +0,0 @@
-p { color:red; }
@@ -1 +0,0 @@
-div { display:none; }
View
@@ -1,11 +0,0 @@
-@import "_global";
-@import "shared/_form";
-
-body {
- color: @text_dark;
-}
-
-form {
- .allforms;
- color: @text_light;
-}
View
@@ -55,6 +55,27 @@ def css_path
"#{Rails.root}/public/css"
end
+ def less_path
+ "#{Rails.root}/less_files"
+ end
+
+ def write_less file, content
+ `mkdir -p #{File.join(less_path, File.dirname(file))}`
+ File.open("#{less_path}/#{file}",'w'){|f| f.print content }
+ end
+
+ def read_css(file)
+ File.read(File.join(css_path, file)) rescue nil
+ end
+
+ def assert_include(item, obj)
+ assert_block("#{obj.inspect}\ndoes not include\n#{item.inspect}."){ obj.include? item }
+ end
+
+ def assert_not_include(item, obj)
+ assert_block("#{obj.inspect}\ndoes include\n#{item.inspect}."){ !obj.include? item }
+ end
+
context :generate do
setup do
Less::More.source_path = 'less_files'
@@ -64,42 +85,40 @@ def css_path
teardown do
`rm -rf #{css_path}`
+ `rm -rf #{less_path}`
+ end
+
+ should "include import partials" do
+ write_less 'test.less', "@import '_partial';\nb{color:blue}"
+ write_less '_partial.less', 'a{color:red}'
+ Less::More.generate_all
+ assert_include 'a { color: red; }', read_css('test.css')
end
- should "include imported partials" do
+ should "not parse partials" do
+ write_less '_partial.less', 'a{color:red}'
Less::More.generate_all
- css = File.read(File.join(css_path, 'test.css'))
- assert css.include?(".allforms { font-size: 110%; }
-body { color: #222222; }
-form {
- font-size: 110%;
- color: #ffffff;
-}")
+ assert_equal '', `ls #{css_path}`.strip
end
should "not parse css" do
+ write_less 'test.css', 'a{color:red}'
Less::More.generate_all
- original_css = File.read(File.join(css_path, 'plain.css'))
- assert_equal File.read(File.join(Rails.root,'less_files', 'plain.css')), original_css
+ assert_equal 'a{color:red}', read_css('test.css')
end
should "add disclaimer-header when active" do
+ write_less 'test.less', 'a{color:red}'
Less::More.header = true
Less::More.generate_all
- css = File.read(File.join(css_path, 'test.css'))
- assert_match /^\/\*/, css # starts with comment -> header
+ assert_match /^\/\*/, read_css('test.css')
end
should "not include header when not set" do
+ write_less 'test.less', 'a{color:red}'
Less::More.header = false
Less::More.generate_all
- css = File.read(File.join(css_path, 'test.css'))
- assert_match /^\.allforms/, css
- end
-
- should "not generate partials" do
- Less::More.generate_all
- assert !File.exist?(File.join(css_path, '_global.css'))
+ assert_not_include '/*', read_css('test.css')
end
end
end

0 comments on commit d2580e2

Please sign in to comment.