rack-less 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +15 -19
- data/README.rdoc +9 -7
- data/Rakefile +3 -3
- data/lib/rack/less/base.rb +1 -1
- data/lib/rack/less/config.rb +1 -1
- data/lib/rack/less/response.rb +4 -4
- data/lib/rack/less/source.rb +6 -1
- data/lib/rack/less/version.rb +2 -2
- data/rack-less.gemspec +4 -3
- data/test/app_helper.rb +3 -3
- data/test/bootstrap_test.rb +26 -0
- data/test/config_test.rb +112 -150
- data/test/fixtures/bootstrap_v1.1.0/bootstrap-1.1.0.css +1894 -0
- data/test/fixtures/bootstrap_v1.1.0/bootstrap.less +23 -0
- data/test/fixtures/bootstrap_v1.1.0/forms.less +369 -0
- data/test/fixtures/bootstrap_v1.1.0/patterns.less +683 -0
- data/test/fixtures/bootstrap_v1.1.0/preboot.less +267 -0
- data/test/fixtures/bootstrap_v1.1.0/reset.less +21 -0
- data/test/fixtures/bootstrap_v1.1.0/scaffolding.less +174 -0
- data/test/fixtures/bootstrap_v1.1.0/tables.less +148 -0
- data/test/fixtures/bootstrap_v1.1.0/type.less +185 -0
- data/test/fixtures/sinatra/app/stylesheets/all_compiled.css +7 -3
- data/test/fixtures/sinatra/app/stylesheets/nested/file_compiled.css +6 -2
- data/test/fixtures/sinatra/app/stylesheets/nested/nested_import.less +3 -0
- data/test/fixtures/sinatra/app/stylesheets/nested/really/really.less +5 -3
- data/test/fixtures/sinatra/app/stylesheets/nested/really/really_compiled.css +7 -2
- data/test/fixtures/sinatra/app/stylesheets/nested/really/really_nested_import.less +4 -0
- data/test/fixtures/sinatra/app/stylesheets/normal.less +1 -1
- data/test/fixtures/sinatra/app/stylesheets/normal_compiled.css +6 -2
- data/test/helper.rb +35 -38
- data/test/irb.rb +9 -0
- data/test/options_test.rb +25 -22
- data/test/request_test.rb +86 -74
- data/test/response_test.rb +6 -4
- data/test/sinatra_test.rb +38 -37
- data/test/source_test.rb +128 -114
- metadata +57 -34
- data/.bundle/config +0 -2
- data/test/env.rb +0 -9
data/test/irb.rb
ADDED
data/test/options_test.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'rack/less/options'
|
3
|
-
require 'fixtures/mock_options'
|
3
|
+
require 'test/fixtures/mock_options'
|
4
4
|
|
5
|
-
|
6
|
-
|
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',
|
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
|
16
|
+
assert_respond_to :option_name, MockOptions
|
15
17
|
end
|
16
18
|
|
17
19
|
should "provide defaults" do
|
18
|
-
assert_respond_to
|
20
|
+
assert_respond_to :defaults, MockOptions
|
19
21
|
end
|
20
22
|
|
21
23
|
should "allow access to the options" do
|
22
|
-
assert_respond_to
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
data/test/request_test.rb
CHANGED
@@ -1,137 +1,149 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'rack/less/request'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
38
|
+
req = less_request("GET", "/something.css")
|
39
|
+
req.options = {:hosted_at => "//there"}
|
40
|
+
assert_equal "/there", req.hosted_at_option
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
req = less_request("GET", "/something.css")
|
43
|
+
req.options = {:hosted_at => "/where/"}
|
44
|
+
assert_equal "/where", req.hosted_at_option
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
req = less_request("GET", "/something.css")
|
47
|
+
req.options = {:hosted_at => "what/"}
|
48
|
+
assert_equal "/what", req.hosted_at_option
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
75
|
+
assert_equal false, req.source.cache?
|
76
|
+
assert_equal nil, req.source.cache
|
77
|
+
end
|
82
78
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
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",
|
data/test/response_test.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'rack/less/response'
|
3
3
|
|
4
|
-
|
4
|
+
module Rack::Less
|
5
5
|
|
6
|
-
|
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,
|
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
|
data/test/sinatra_test.rb
CHANGED
@@ -1,54 +1,55 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require "test/app_helper"
|
3
3
|
require 'test/fixtures/sinatra/app'
|
4
4
|
|
5
|
-
|
5
|
+
module Rack::Less
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
14
|
+
app.use Rack::Less,
|
15
|
+
:root => file_path('test','fixtures','sinatra')
|
26
16
|
end
|
27
17
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
:root => file_path('test','fixtures','sinatra')
|
18
|
+
def app
|
19
|
+
@app ||= SinatraApp
|
20
|
+
end
|
32
21
|
|
33
|
-
|
34
|
-
@response = visit "/stylesheets/nested/file.css"
|
35
|
-
end
|
22
|
+
end
|
36
23
|
|
37
|
-
|
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
|
-
|
41
|
-
|
42
|
-
app.use Rack::Less,
|
43
|
-
:root => file_path('test','fixtures','sinatra')
|
31
|
+
should_respond_with_compiled_css
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
|
-
|
54
|
+
|
55
|
+
end
|
data/test/source_test.rb
CHANGED
@@ -1,158 +1,172 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'rack/less/source'
|
3
3
|
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
-
|
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],
|
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
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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
|