rack-less 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +5 -4
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +15 -19
  4. data/README.rdoc +9 -7
  5. data/Rakefile +3 -3
  6. data/lib/rack/less/base.rb +1 -1
  7. data/lib/rack/less/config.rb +1 -1
  8. data/lib/rack/less/response.rb +4 -4
  9. data/lib/rack/less/source.rb +6 -1
  10. data/lib/rack/less/version.rb +2 -2
  11. data/rack-less.gemspec +4 -3
  12. data/test/app_helper.rb +3 -3
  13. data/test/bootstrap_test.rb +26 -0
  14. data/test/config_test.rb +112 -150
  15. data/test/fixtures/bootstrap_v1.1.0/bootstrap-1.1.0.css +1894 -0
  16. data/test/fixtures/bootstrap_v1.1.0/bootstrap.less +23 -0
  17. data/test/fixtures/bootstrap_v1.1.0/forms.less +369 -0
  18. data/test/fixtures/bootstrap_v1.1.0/patterns.less +683 -0
  19. data/test/fixtures/bootstrap_v1.1.0/preboot.less +267 -0
  20. data/test/fixtures/bootstrap_v1.1.0/reset.less +21 -0
  21. data/test/fixtures/bootstrap_v1.1.0/scaffolding.less +174 -0
  22. data/test/fixtures/bootstrap_v1.1.0/tables.less +148 -0
  23. data/test/fixtures/bootstrap_v1.1.0/type.less +185 -0
  24. data/test/fixtures/sinatra/app/stylesheets/all_compiled.css +7 -3
  25. data/test/fixtures/sinatra/app/stylesheets/nested/file_compiled.css +6 -2
  26. data/test/fixtures/sinatra/app/stylesheets/nested/nested_import.less +3 -0
  27. data/test/fixtures/sinatra/app/stylesheets/nested/really/really.less +5 -3
  28. data/test/fixtures/sinatra/app/stylesheets/nested/really/really_compiled.css +7 -2
  29. data/test/fixtures/sinatra/app/stylesheets/nested/really/really_nested_import.less +4 -0
  30. data/test/fixtures/sinatra/app/stylesheets/normal.less +1 -1
  31. data/test/fixtures/sinatra/app/stylesheets/normal_compiled.css +6 -2
  32. data/test/helper.rb +35 -38
  33. data/test/irb.rb +9 -0
  34. data/test/options_test.rb +25 -22
  35. data/test/request_test.rb +86 -74
  36. data/test/response_test.rb +6 -4
  37. data/test/sinatra_test.rb +38 -37
  38. data/test/source_test.rb +128 -114
  39. metadata +57 -34
  40. data/.bundle/config +0 -2
  41. data/test/env.rb +0 -9
@@ -0,0 +1,9 @@
1
+ require 'assert/setup'
2
+
3
+ # this file is required in when the 'irb' rake test is run.
4
+ # b/c 'assert/setup' is required above, the test helper will be
5
+ # required in.
6
+
7
+ # put any IRB setup code here
8
+
9
+ require 'rack/less'
@@ -1,25 +1,27 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'rack/less/options'
3
- require 'fixtures/mock_options'
3
+ require 'test/fixtures/mock_options'
4
4
 
5
- class OptionsTest < Test::Unit::TestCase
6
- context 'Rack::Less::Options' do
5
+ module Rack::Less
6
+
7
+ class OptionsTest < Assert::Context
8
+ desc 'Rack::Less::Options'
7
9
  setup { @options = MockOptions.new }
8
10
 
9
11
  should "use a namespace" do
10
- assert_equal 'rack-less', Rack::Less::Options::RACK_ENV_NS
12
+ assert_equal 'rack-less', Options::RACK_ENV_NS
11
13
  end
12
14
 
13
15
  should "provide an option_name helper" do
14
- assert_respond_to MockOptions, :option_name
16
+ assert_respond_to :option_name, MockOptions
15
17
  end
16
18
 
17
19
  should "provide defaults" do
18
- assert_respond_to MockOptions, :defaults
20
+ assert_respond_to :defaults, MockOptions
19
21
  end
20
22
 
21
23
  should "allow access to the options" do
22
- assert_respond_to @options, :options, 'no #options accessor'
24
+ assert_respond_to :options, @options, 'no #options accessor'
23
25
  assert_kind_of Hash, @options.options, '#options is not a Hash'
24
26
  assert_equal MockOptions.defaults[MockOptions.option_name(:source)], @options.options(:source)
25
27
  end
@@ -34,20 +36,20 @@ class OptionsTest < Test::Unit::TestCase
34
36
  end
35
37
  end
36
38
 
37
- context '#set' do
38
- should "set a Symbol option as #{Rack::Less::Options::RACK_ENV_NS}.symbol" do
39
- @options.set :foo, 'bar'
40
- assert_equal 'bar', @options.options[MockOptions.option_name(:foo)]
41
- end
42
- should 'set a String option as string' do
43
- @options.set 'foo.bar', 'baz'
44
- assert_equal 'baz', @options.options['foo.bar']
45
- end
46
- should 'set all key/value pairs when given a Hash' do
47
- @options.set :foo => 'bar', 'foo.bar' => 'baz'
48
- assert_equal 'bar', @options.options[MockOptions.option_name(:foo)]
49
- assert_equal 'baz', @options.options['foo.bar']
50
- end
39
+ should "set a Symbol option as #{Options::RACK_ENV_NS}.symbol" do
40
+ @options.set :foo, 'bar'
41
+ assert_equal 'bar', @options.options[MockOptions.option_name(:foo)]
42
+ end
43
+
44
+ should 'set a String option as string' do
45
+ @options.set 'foo.bar', 'baz'
46
+ assert_equal 'baz', @options.options['foo.bar']
47
+ end
48
+
49
+ should 'set all key/value pairs when given a Hash' do
50
+ @options.set :foo => 'bar', 'foo.bar' => 'baz'
51
+ assert_equal 'bar', @options.options[MockOptions.option_name(:foo)]
52
+ assert_equal 'baz', @options.options['foo.bar']
51
53
  end
52
54
 
53
55
  should 'allow setting multiple options via assignment' do
@@ -57,4 +59,5 @@ class OptionsTest < Test::Unit::TestCase
57
59
  end
58
60
 
59
61
  end
62
+
60
63
  end
@@ -1,137 +1,149 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'rack/less/request'
3
3
 
4
- class RequestTest < Test::Unit::TestCase
5
-
6
- context 'Rack::Less::Request' do
7
- setup do
8
- @defaults = env_defaults
9
- end
10
-
11
- context "basic object" do
12
- should "have some attributes" do
13
- [ :options,
14
- :hosted_at_option,
15
- :request_method,
16
- :path_info,
17
- :path_info_format,
18
- :path_info_resource,
19
- :source,
20
- :hosted_at?,
21
- :cached?,
22
- :for_css?,
23
- :for_less?
24
- ].each do |a|
25
- assert_respond_to less_request("GET", "/foo.css"), a, "request does not respond to #{a.inspect}"
26
- end
4
+ module Rack::Less
5
+
6
+ class RequestTests < Assert::Context
7
+ desc 'Rack::Less::Request'
8
+ setup { @defaults = env_defaults }
9
+
10
+ should "have some attributes" do
11
+ [ :options,
12
+ :hosted_at_option,
13
+ :request_method,
14
+ :path_info,
15
+ :path_info_format,
16
+ :path_info_resource,
17
+ :source,
18
+ :hosted_at?,
19
+ :cached?,
20
+ :for_css?,
21
+ :for_less?
22
+ ].each do |a|
23
+ assert_respond_to a, less_request("GET", "/foo.css"), "request does not respond to #{a.inspect}"
27
24
  end
25
+ end
28
26
 
29
- should "know it's resource format" do
30
- assert_equal '.css', less_request("GET", "/foo.css").path_info_format
31
- assert_equal '.css', less_request("GET", "/foo/bar.css").path_info_format
32
- assert_equal '', less_request("GET", "/foo/bar").path_info_format
33
- end
27
+ should "know it's resource format" do
28
+ assert_equal '.css', less_request("GET", "/foo.css").path_info_format
29
+ assert_equal '.css', less_request("GET", "/foo/bar.css").path_info_format
30
+ assert_equal '', less_request("GET", "/foo/bar").path_info_format
31
+ end
34
32
 
35
- should "sanitize the :hosted_at options" do
36
- req = less_request("GET", "/something.css")
37
- req.options = {:hosted_at => "/here"}
38
- assert_equal "/here", req.hosted_at_option
33
+ should "sanitize the :hosted_at options" do
34
+ req = less_request("GET", "/something.css")
35
+ req.options = {:hosted_at => "/here"}
36
+ assert_equal "/here", req.hosted_at_option
39
37
 
40
- req = less_request("GET", "/something.css")
41
- req.options = {:hosted_at => "//there"}
42
- assert_equal "/there", req.hosted_at_option
38
+ req = less_request("GET", "/something.css")
39
+ req.options = {:hosted_at => "//there"}
40
+ assert_equal "/there", req.hosted_at_option
43
41
 
44
- req = less_request("GET", "/something.css")
45
- req.options = {:hosted_at => "/where/"}
46
- assert_equal "/where", req.hosted_at_option
42
+ req = less_request("GET", "/something.css")
43
+ req.options = {:hosted_at => "/where/"}
44
+ assert_equal "/where", req.hosted_at_option
47
45
 
48
- req = less_request("GET", "/something.css")
49
- req.options = {:hosted_at => "what/"}
50
- assert_equal "/what", req.hosted_at_option
46
+ req = less_request("GET", "/something.css")
47
+ req.options = {:hosted_at => "what/"}
48
+ assert_equal "/what", req.hosted_at_option
51
49
 
52
- req = less_request("GET", "/something.css")
53
- req.options = {:hosted_at => "why//"}
54
- assert_equal "/why", req.hosted_at_option
55
- end
50
+ req = less_request("GET", "/something.css")
51
+ req.options = {:hosted_at => "why//"}
52
+ assert_equal "/why", req.hosted_at_option
53
+ end
56
54
 
57
- should "know it's resource" do
58
- assert_equal '/something', less_request("GET", "/stylesheets/something.css").path_info_resource
59
- assert_equal '/something.awesome', less_request("GET", "/stylesheets/something.awesome.css").path_info_resource
60
- assert_equal '/nested/something', less_request("GET", "/stylesheets/nested/something.css").path_info_resource
61
- assert_equal '/something/really/awesome', less_request("GET", "/stylesheets/something/really/awesome.css").path_info_resource
62
- assert_equal '/something', less_request("GET", "/something.css").path_info_resource
63
- assert_equal '/something', less_request("GET", "///something.css").path_info_resource
64
- assert_equal '/nested/something', less_request("GET", "/nested/something.css").path_info_resource
65
- assert_equal '/nested/something', less_request("GET", "/nested///something.css").path_info_resource
66
- end
55
+ should "know it's resource" do
56
+ assert_equal '/something', less_request("GET", "/stylesheets/something.css").path_info_resource
57
+ assert_equal '/something.awesome', less_request("GET", "/stylesheets/something.awesome.css").path_info_resource
58
+ assert_equal '/nested/something', less_request("GET", "/stylesheets/nested/something.css").path_info_resource
59
+ assert_equal '/something/really/awesome', less_request("GET", "/stylesheets/something/really/awesome.css").path_info_resource
60
+ assert_equal '/something', less_request("GET", "/something.css").path_info_resource
61
+ assert_equal '/something', less_request("GET", "///something.css").path_info_resource
62
+ assert_equal '/nested/something', less_request("GET", "/nested/something.css").path_info_resource
63
+ assert_equal '/nested/something', less_request("GET", "/nested///something.css").path_info_resource
67
64
  end
68
65
 
69
- context "#source " do
70
- should "match :compress settings with Rack::Less:Config" do
71
- req = less_request("GET", "/stylesheets/normal.css")
72
- assert_equal Rack::Less.config.compress?, req.source.compress?
73
- end
66
+ should "match source :compress settings with Rack::Less:Config" do
67
+ req = less_request("GET", "/stylesheets/normal.css")
68
+ assert_equal Rack::Less.config.compress?, req.source.compress?
69
+ end
74
70
 
75
- should "set it's cache value to nil when Rack::Less not configured to cache" do
76
- Rack::Less.config = Rack::Less::Config.new
77
- req = less_request("GET", "/stylesheets/normal.css")
71
+ should "set it's source cache value to nil when Rack::Less not configured to cache" do
72
+ Rack::Less.config = Rack::Less::Config.new
73
+ req = less_request("GET", "/stylesheets/normal.css")
78
74
 
79
- assert_equal false, req.source.cache?
80
- assert_equal nil, req.source.cache
81
- end
75
+ assert_equal false, req.source.cache?
76
+ assert_equal nil, req.source.cache
77
+ end
82
78
 
83
- should "set it's cache to the appropriate path when Rack::Less configured to cache" do
84
- Rack::Less.config = Rack::Less::Config.new :cache => true
85
- req = less_request("GET", "/stylesheets/normal.css")
86
- cache_path = File.join(req.options(:root), req.options(:public), req.hosted_at_option)
79
+ should "set it's source cache to the appropriate path when Rack::Less configured to cache" do
80
+ Rack::Less.config = Rack::Less::Config.new :cache => true
81
+ req = less_request("GET", "/stylesheets/normal.css")
82
+ cache_path = File.join(req.options(:root), req.options(:public), req.hosted_at_option)
87
83
 
88
- assert_equal true, req.source.cache?
89
- assert_equal cache_path, req.source.cache
90
- end
84
+ assert_equal true, req.source.cache?
85
+ assert_equal cache_path, req.source.cache
91
86
  end
92
87
 
88
+ end
89
+
90
+ class ReqInvalidPostNonCssTests < RequestTests
93
91
  should_not_be_a_valid_rack_less_request({
94
92
  :method => "POST",
95
93
  :resource => "/foo.html",
96
94
  :description => "a non-css resource"
97
95
  })
96
+ end
98
97
 
98
+ class ReqInvalidPostCssTests < RequestTests
99
99
  should_not_be_a_valid_rack_less_request({
100
100
  :method => "POST",
101
101
  :resource => "/foo.css",
102
102
  :description => "a css resource"
103
103
  })
104
+ end
104
105
 
106
+ class ReqInvalidBadHostTests < RequestTests
105
107
  should_not_be_a_valid_rack_less_request({
106
108
  :method => "GET",
107
109
  :resource => "/foo.css",
108
110
  :description => "a css resource hosted somewhere other than where Rack::Less expects them"
109
111
  })
112
+ end
110
113
 
114
+ class ReqInvalidNoSourceTests < RequestTests
111
115
  should_not_be_a_valid_rack_less_request({
112
116
  :method => "GET",
113
117
  :resource => "/stylesheets/foo.css",
114
118
  :description => "a css resource hosted where Rack::Less expects them but does not match any source"
115
119
  })
120
+ end
116
121
 
122
+ class ReqValidHostedMatchedTests < RequestTests
117
123
  should_be_a_valid_rack_less_request({
118
124
  :method => "GET",
119
125
  :resource => "/stylesheets/normal.css",
120
126
  :description => "a css resource hosted where Rack::Less expects them that matches source"
121
127
  })
128
+ end
122
129
 
130
+ class ReqValidWithDashTests < RequestTests
123
131
  should_be_a_valid_rack_less_request({
124
132
  :method => "GET",
125
133
  :resource => "/stylesheets/some-styles.css",
126
134
  :description => "a proper css resource with a '-' in the name"
127
135
  })
136
+ end
128
137
 
138
+ class ReqValidUnderscoreTests < RequestTests
129
139
  should_be_a_valid_rack_less_request({
130
140
  :method => "GET",
131
141
  :resource => "/stylesheets/some_styles.css",
132
142
  :description => "a proper css resource with a '_' in the name"
133
143
  })
144
+ end
134
145
 
146
+ class ReqValidNumberedTests < RequestTests
135
147
  should_be_a_valid_rack_less_request({
136
148
  :method => "GET",
137
149
  :resource => "/stylesheets/styles1.css",
@@ -1,9 +1,10 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'rack/less/response'
3
3
 
4
- class RequestTest < Test::Unit::TestCase
4
+ module Rack::Less
5
5
 
6
- context 'Rack::Less::Response' do
6
+ class ResponseTests < Assert::Context
7
+ desc 'Rack::Less::Response'
7
8
  setup do
8
9
  @defaults = env_defaults
9
10
  @css = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'css_compiled.css'))
@@ -19,7 +20,7 @@ class RequestTest < Test::Unit::TestCase
19
20
  :content_type,
20
21
  :to_rack
21
22
  ].each do |a|
22
- assert_respond_to @response, a, "request does not respond to #{a.inspect}"
23
+ assert_respond_to a, @response, "request does not respond to #{a.inspect}"
23
24
  end
24
25
  end
25
26
 
@@ -36,6 +37,7 @@ class RequestTest < Test::Unit::TestCase
36
37
  assert_equal Rack::Less::Response.content_length(@css), @response.content_length, 'the content_length accessor is incorrect'
37
38
  assert_equal Rack::Less::Response.content_length(@css), @response.headers['Content-Length'].to_i
38
39
  end
40
+
39
41
  end
40
42
 
41
43
  end
@@ -1,54 +1,55 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require "test/app_helper"
3
3
  require 'test/fixtures/sinatra/app'
4
4
 
5
- class SinatraTest < Test::Unit::TestCase
5
+ module Rack::Less
6
6
 
7
- def app
8
- @app ||= SinatraApp
9
- end
10
- def default_value(name)
11
- Rack::Less::Base.defaults["#{Rack::Less::Options::RACK_ENV_NS}.#{name}"]
12
- end
13
-
14
- context "A Sinatra app using Rack::Less" do
15
-
16
- context "requesting valid LESS" do
17
- setup do
18
- app.use Rack::Less,
19
- :root => file_path('test','fixtures','sinatra')
20
-
21
- @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'normal_compiled.css'))
22
- @response = visit "/stylesheets/normal.css"
7
+ class SinatraTests < Assert::Context
8
+ desc "rack less hosted by a sinatra app"
9
+ setup do
10
+ Rack::Less.configure do |config|
11
+ config.compress = false
12
+ config.cache = false
23
13
  end
24
-
25
- should_respond_with_compiled_css
14
+ app.use Rack::Less,
15
+ :root => file_path('test','fixtures','sinatra')
26
16
  end
27
17
 
28
- context "requesting a nested valid LESS" do
29
- setup do
30
- app.use Rack::Less,
31
- :root => file_path('test','fixtures','sinatra')
18
+ def app
19
+ @app ||= SinatraApp
20
+ end
32
21
 
33
- @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'nested', 'file_compiled.css'))
34
- @response = visit "/stylesheets/nested/file.css"
35
- end
22
+ end
36
23
 
37
- should_respond_with_compiled_css
24
+ class SinatraValidCss < SinatraTests
25
+ desc "requesting valid LESS"
26
+ setup do
27
+ @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'normal_compiled.css'))
28
+ @response = visit "/stylesheets/normal.css"
38
29
  end
39
30
 
40
- context "requesting a really nested valid LESS" do
41
- setup do
42
- app.use Rack::Less,
43
- :root => file_path('test','fixtures','sinatra')
31
+ should_respond_with_compiled_css
32
+ end
44
33
 
45
- @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'nested', 'really', 'really_compiled.css'))
46
- @response = visit "/stylesheets/nested/really/really.css"
47
- end
34
+ class SinatraNestedValidCss < SinatraTests
35
+ desc "requesting a nested valid LESS"
36
+ setup do
37
+ @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'nested', 'file_compiled.css'))
38
+ @response = visit "/stylesheets/nested/file.css"
39
+ end
48
40
 
49
- should_respond_with_compiled_css
41
+ should_respond_with_compiled_css
42
+ end
43
+
44
+ class SinatraReallyNestedValidCss < SinatraTests
45
+ desc "requesting a really nested valid LESS"
46
+ setup do
47
+ @compiled = File.read(file_path('test','fixtures','sinatra','app','stylesheets', 'nested', 'really', 'really_compiled.css'))
48
+ @response = visit "/stylesheets/nested/really/really.css"
50
49
  end
51
50
 
51
+ should_respond_with_compiled_css
52
52
  end
53
53
 
54
- end
54
+
55
+ end
@@ -1,158 +1,172 @@
1
- require "test/helper"
1
+ require "assert"
2
2
  require 'rack/less/source'
3
3
 
4
- class SourceTest < Test::Unit::TestCase
5
- context 'Rack::Less::Source' do
4
+ module Rack::Less
5
+
6
+ class SourceTests < Assert::Context
7
+ desc 'Rack::Less::Source'
6
8
  setup do
7
9
  @source_folder = file_path('test','fixtures','sinatra','app','stylesheets')
8
10
  @cache = file_path('test','fixtures','sinatra','public','stylesheets')
9
11
  end
10
12
 
11
13
  should "require an existing :folder" do
14
+ assert_raise(ArgumentError) { Source.new('foo') }
12
15
  assert_raise ArgumentError do
13
- Rack::Less::Source.new('foo')
14
- end
15
- assert_raise ArgumentError do
16
- Rack::Less::Source.new('foo', :folder => file_path('does','not','exist'))
16
+ Source.new('foo', :folder => file_path('does','not','exist'))
17
17
  end
18
18
  assert_nothing_raised do
19
- Rack::Less::Source.new('foo', :folder => @source_folder)
19
+ Source.new('foo', :folder => @source_folder)
20
20
  end
21
21
  end
22
22
 
23
23
  should "accept both .less and .css extensions, prefering .less over .css though" do
24
- assert_equal [:less, :css], Rack::Less::Source::PREFERRED_EXTENSIONS
25
- end
26
-
27
- context "object" do
28
- setup do
29
- @basic = Rack::Less::Source.new('basic', :folder => @source_folder)
30
- @nested = Rack::Less::Source.new('this/source/is/nested', :folder => @source_folder)
31
- @ugly = Rack::Less::Source.new('//this/source/is/ugly', :folder => @source_folder)
32
- @compressed = Rack::Less::Source.new('compressed', {
33
- :folder => @source_folder,
34
- :compress => true
35
- })
36
- @cached = Rack::Less::Source.new('cached', {
37
- :folder => @source_folder,
38
- :cache => @cache,
39
- :compress => false
40
- })
41
- end
24
+ assert_equal [:less, :css], Source::PREFERRED_EXTENSIONS
25
+ end
42
26
 
43
- should "have accessors for path and cache values" do
44
- assert_respond_to @basic, :css_resource
45
- assert_equal 'basic', @basic.css_resource
46
- assert_respond_to @basic, :cache
47
- assert_equal 'this/source/is/nested', @nested.css_resource
48
- assert_equal 'this/source/is/ugly', @ugly.css_resource
49
- end
27
+ end
50
28
 
51
- should "have an option for using compression" do
52
- assert_equal false, @basic.compress?, 'the basic app should not compress'
53
- assert_equal true, @compressed.compress?, 'the compressed app should compress'
54
- assert_equal false, @cached.compress?, 'the cached app should not compress'
55
- end
29
+ class SourceTypesTests < SourceTests
30
+ setup do
31
+ @basic = Source.new('basic', :folder => @source_folder)
32
+ @nested = Source.new('this/source/is/nested', :folder => @source_folder)
33
+ @ugly = Source.new('//this/source/is/ugly', :folder => @source_folder)
34
+ @compressed = Source.new('compressed', {
35
+ :folder => @source_folder,
36
+ :compress => true
37
+ })
38
+ @cached = Source.new('cached', {
39
+ :folder => @source_folder,
40
+ :cache => @cache,
41
+ :compress => false
42
+ })
43
+ end
56
44
 
57
- should "have an option for caching output to files" do
58
- assert_equal false, @basic.cache?, 'the basic app should not cache'
59
- assert_equal true, @cached.cache?, 'the cached app should cache'
60
- end
45
+ should "have accessors for path and cache values" do
46
+ assert_respond_to :css_resource, @basic
47
+ assert_equal 'basic', @basic.css_resource
48
+ assert_respond_to :cache, @basic
49
+ assert_equal 'this/source/is/nested', @nested.css_resource
50
+ assert_equal 'this/source/is/ugly', @ugly.css_resource
51
+ end
61
52
 
62
- should "have a source files list" do
63
- assert_respond_to @basic, :files, 'engine does not respond to :files'
64
- assert_kind_of Array, @basic.files, 'the engine files is not an Array'
65
- end
53
+ should "have an option for using compression" do
54
+ assert_equal false, @basic.compress?, 'the basic app should not compress'
55
+ assert_equal true, @compressed.compress?, 'the compressed app should compress'
56
+ assert_equal false, @cached.compress?, 'the cached app should not compress'
57
+ end
66
58
 
67
- should "have compiled css" do
68
- assert_respond_to @basic, :to_css, 'engine does not respond to :to_css'
69
- assert_respond_to @basic, :css, 'engine does not respond to :css'
70
- end
59
+ should "have an option for caching output to files" do
60
+ assert_equal false, @basic.cache?, 'the basic app should not cache'
61
+ assert_equal true, @cached.cache?, 'the cached app should cache'
71
62
  end
72
63
 
73
- context "with no corresponding source" do
74
- setup do
75
- @none = Rack::Less::Source.new('none', :folder => @source_folder)
76
- end
64
+ should "have a source files list" do
65
+ assert_respond_to :files, @basic, 'engine does not respond to :files'
66
+ assert_kind_of Array, @basic.files, 'the engine files is not an Array'
67
+ end
77
68
 
78
- should "have an empty file list" do
79
- assert @none.files.empty?, 'engine file list is not empty'
80
- end
69
+ should "have compiled css" do
70
+ assert_respond_to :to_css, @basic, 'engine does not respond to :to_css'
71
+ assert_respond_to :css, @basic, 'engine does not respond to :css'
72
+ end
73
+ end
81
74
 
82
- should "generate no css" do
83
- assert @none.to_css.empty?, 'engine generated css when it should not have'
84
- end
75
+ class NoSourceTests < SourceTests
76
+ desc "with no corresponding source"
77
+ setup do
78
+ @none = Rack::Less::Source.new('none', :folder => @source_folder)
85
79
  end
86
80
 
81
+ should "have an empty file list" do
82
+ assert @none.files.empty?, 'engine file list is not empty'
83
+ end
84
+
85
+ should "generate no css" do
86
+ assert @none.to_css.empty?, 'engine generated css when it should not have'
87
+ end
88
+ end
89
+
90
+ class NormalSourceCompileTests < SourceTests
87
91
  should_compile_source('normal', "needing to be compiled")
88
- should_compile_source('nested/file', "that is nested, needing to be compiled")
89
- should_compile_source('css', "that is a CSS stylesheet")
92
+ end
90
93
 
94
+ class NestedSourceCompileTests < SourceTests
95
+ should_compile_source('nested/file', "that is nested, needing to be compiled")
96
+ end
91
97
 
92
- context "with whitespace compression" do
93
- setup do
94
- @compiled = File.read(File.join(@source_folder, "normal_compiled.css"))
95
- @compressed_normal = Rack::Less::Source.new('normal', {
96
- :folder => @source_folder,
97
- :compress => :whitespace
98
- })
99
- end
98
+ class CssSourceCompileTests < SourceTests
99
+ should_compile_source('css', "that is a CSS stylesheet")
100
+ end
100
101
 
101
- should "compress the compiled css" do
102
- assert_equal @compiled.strip.delete("\n"), @compressed_normal.to_css, "the compiled css is compressed incorrectly"
103
- end
102
+ class SourceWhitespaceCompressTests < SourceTests
103
+ desc "with whitespace compression"
104
+ setup do
105
+ @compressed_normal = Rack::Less::Source.new('normal', {
106
+ :folder => @source_folder,
107
+ :compress => :whitespace
108
+ })
104
109
  end
105
110
 
106
- context "with yui compression" do
107
- setup do
108
- @compiled = File.read(File.join(@source_folder, "normal_compiled.css"))
109
- @compressed_normal = Rack::Less::Source.new('normal', {
110
- :folder => @source_folder,
111
- :compress => :yui
112
- })
113
- end
111
+ should "compress the compiled css" do
112
+ assert_equal "#header{color:#6c94be;}div{width:2;}", @compressed_normal.to_css, "the compiled css is compressed incorrectly"
113
+ end
114
+ end
114
115
 
115
- should "compress the compiled css" do
116
- comp = YUI::CssCompressor.new(Rack::Less::Source::YUI_OPTS).compress(@compiled.strip)
117
- assert_equal comp, @compressed_normal.to_css, "the compiled css is compressed incorrectly"
118
- end
116
+ class SourceYuiCompressTests < SourceTests
117
+ desc "with yui compression"
118
+ setup do
119
+ @compiled = File.read(File.join(@source_folder, "normal_compiled.css"))
120
+ @compressed_normal = Rack::Less::Source.new('normal', {
121
+ :folder => @source_folder,
122
+ :compress => :yui
123
+ })
119
124
  end
120
125
 
121
- context "with caching" do
122
- setup do
123
- FileUtils.rm_rf(File.dirname(@cache)) if File.exists?(File.dirname(@cache))
124
- @expected = Rack::Less::Source.new('normal', {
125
- :folder => @source_folder,
126
- :cache => @cache
127
- }).to_css
128
- @cached_file = File.join(@cache, "normal.css")
129
- end
130
- teardown do
131
- FileUtils.rm_rf(File.dirname(@cache)) if File.exists?(File.dirname(@cache))
132
- end
126
+ should "compress the compiled css" do
127
+ comp = YUI::CssCompressor.new(Rack::Less::Source::YUI_OPTS).compress(@compiled.strip)
128
+ assert_equal comp, @compressed_normal.to_css, "the compiled css is compressed incorrectly"
129
+ end
130
+ end
133
131
 
134
- should "store the compiled css to a file in the cache" do
135
- assert File.exists?(@cache), 'the cache folder does not exist'
136
- assert File.exists?(@cached_file), 'the css was not cached to a file'
137
- assert_equal @expected.strip, File.read(@cached_file).strip, "the compiled css is incorrect"
132
+ class SourceCachingTests < SourceTests
133
+ desc "with caching"
134
+ setup do
135
+ FileUtils.rm_rf(File.dirname(@cache)) if File.exists?(File.dirname(@cache))
136
+ @expected = Rack::Less::Source.new('normal', {
137
+ :folder => @source_folder,
138
+ :cache => @cache
139
+ }).to_css
140
+ @cached_file = File.join(@cache, "normal.css")
141
+ end
142
+ teardown do
143
+ if File.exists?(File.dirname(@cache))
144
+ FileUtils.rm_rf(File.dirname(@cache))
138
145
  end
139
146
  end
140
147
 
141
- context "that is a combination of multiple files" do
142
- setup do
143
- @compiled = File.read(File.join(@source_folder, "all_compiled.css"))
144
- @combinations_before = Rack::Less.config.combinations
145
- Rack::Less.config.combinations = {'all' => ['all_one', 'all_two']}
146
- @all = Rack::Less::Source.new('all', :folder => @source_folder)
147
- end
148
- teardown do
149
- Rack::Less.config.combinations = @combinations_before
150
- end
148
+ should "store the compiled css to a file in the cache" do
149
+ assert File.exists?(@cache), 'the cache folder does not exist'
150
+ assert File.exists?(@cached_file), 'the css was not cached to a file'
151
+ assert_equal @expected.strip, File.read(@cached_file).strip, "the compiled css is incorrect"
152
+ end
153
+ end
151
154
 
152
- should "combine the compiled css" do
153
- assert_equal @compiled.strip, @all.to_css.strip, "the compiled css is combined incorrectly"
154
- end
155
+ class MultipleSourceTests < SourceTests
156
+ desc "that is a combination of multiple files"
157
+ setup do
158
+ @compiled = File.read(File.join(@source_folder, "all_compiled.css"))
159
+ @combinations_before = Rack::Less.config.combinations
160
+ Rack::Less.config.combinations = {'all' => ['all_one', 'all_two']}
161
+ @all = Rack::Less::Source.new('all', :folder => @source_folder)
162
+ end
163
+ teardown do
164
+ Rack::Less.config.combinations = @combinations_before
155
165
  end
156
166
 
167
+ should "combine the compiled css" do
168
+ assert_equal @compiled.strip, @all.to_css.strip, "the compiled css is combined incorrectly"
169
+ end
157
170
  end
171
+
158
172
  end