Permalink
Browse files

add specs for remove_all_generated

  • Loading branch information...
1 parent 7817005 commit 620e635247d602e4cc58d90aebcf5630d3d96205 @grosser grosser committed Feb 13, 2010
Showing with 46 additions and 2 deletions.
  1. +46 −2 test/more_test.rb
View
@@ -60,8 +60,16 @@ def less_path
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 }
+ write_content File.join(less_path, file), content
+ end
+
+ def write_css file, content
+ write_content File.join(css_path, file), content
+ end
+
+ def write_content file, content
+ `mkdir -p #{File.dirname(file)}`
+ File.open(file,'w'){|f| f.print content }
end
def read_css(file)
@@ -94,6 +102,12 @@ def assert_not_include(item, obj)
assert_include 'a { color: red; }', read_css('test.css')
end
+ should 'generate for files in subfolders' do
+ write_less 'xxx/test.less', "a{color:red}"
+ Less::More.generate_all
+ assert_include 'a { color: red; }', read_css('xxx/test.css')
+ end
+
should "include imported partials" do
write_less 'test.less', "@import '_partial';\nb{color:blue}"
write_less '_partial.less', 'a{color:red}'
@@ -138,4 +152,34 @@ def assert_not_include(item, obj)
assert_include '/test.less', content
end
end
+
+ context :remove_all_generated do
+ setup do
+ Less::More.source_path = 'less_files'
+ Less::More.destination_path = 'css'
+ `mkdir -p #{css_path}`
+ end
+
+ teardown do
+ `rm -rf #{css_path}`
+ `rm -rf #{less_path}`
+ end
+
+ should "remove all generated css" do
+ write_less 'xxx.less', 'a{color:red}'
+ write_less 'yyy.css', 'a{color:red}'
+ write_less 'xxx/yyy.css', 'a{color:red}'
+ Less::More.generate_all
+ Less::More.remove_all_generated
+ # should be '' ideally, but an empty folder is no thread :)
+ assert_equal 'xxx', `ls #{css_path}`.strip
+ end
+
+ should "not remove other files" do
+ write_css 'xxx.css', 'a{color:red}'
+ Less::More.generate_all
+ Less::More.remove_all_generated
+ assert_equal 'xxx.css', `ls #{css_path}`.strip
+ end
+ end
end

0 comments on commit 620e635

Please sign in to comment.