1
1
require 'test_helper'
2
2
3
3
class SassRailsTest < Sass ::Rails ::TestCase
4
- test " classes are loaded" do
4
+ test ' classes are loaded' do
5
5
assert_kind_of Module , Sass ::Rails
6
- assert_kind_of Class , Sass ::Rails ::CssCompressor
7
6
assert_kind_of Class , Sass ::Rails ::Railtie
8
7
end
9
8
10
- test 'style config item is honored' do
9
+ test 'style config item is honored in development mode ' do
11
10
within_rails_app 'alternate_config_project' do
12
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , " Gemfile" , { " RAILS_ENV" => " development" }
11
+ runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , ' Gemfile' , { ' RAILS_ENV' => ' development' }
13
12
assert_output /compact/
14
13
end
15
14
end
16
15
16
+ test 'style config item is not honored if environment is not development' do
17
+ within_rails_app 'alternate_config_project' do
18
+ runcmd "ruby script/rails runner 'p Rails.application.config.sass.style'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'production' }
19
+ assert_equal 'nil' , $last_ouput. chomp
20
+ end
21
+ end
22
+
17
23
test 'css_compressor config item is not honored in development mode' do
18
24
within_rails_app 'alternate_config_project' do
19
- runcmd "ruby script/rails runner 'p Rails.application.config.assets.css_compressor'" , Dir . pwd , true , " Gemfile" , { " RAILS_ENV" => " development" }
25
+ runcmd "ruby script/rails runner 'p Rails.application.config.assets.css_compressor'" , Dir . pwd , true , ' Gemfile' , { ' RAILS_ENV' => ' development' }
20
26
assert_equal 'nil' , $last_ouput. chomp
21
27
end
22
28
end
23
29
24
30
test 'css_compressor config item is honored if environment is not development' do
25
31
within_rails_app 'alternate_config_project' do
26
- runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'" , Dir . pwd , true , " Gemfile" , { " RAILS_ENV" => " production" }
32
+ runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'" , Dir . pwd , true , ' Gemfile' , { ' RAILS_ENV' => ' production' }
27
33
assert_output /yui/
28
34
end
29
35
end
30
36
31
37
test 'sass uses expanded style by default in development mode' do
32
38
within_rails_app 'scss_project' do
33
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , " Gemfile" , { 'RAILS_ENV' => 'development' }
39
+ runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , ' Gemfile' , { 'RAILS_ENV' => 'development' }
34
40
assert_output /expanded/
35
41
end
36
42
end
37
43
38
- test 'sass uses compressed style by default in test mode' do
39
- within_rails_app 'scss_project' do
40
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'test' }
41
- assert_output /compressed/
42
- end
43
- end
44
-
45
- test 'sass uses compressed style by default in production mode' do
46
- within_rails_app 'scss_project' do
47
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'production' }
48
- assert_output /compressed/
49
- end
50
- end
51
-
52
44
test 'sass not defines compressor in development mode' do
53
45
within_rails_app 'scss_project' do
54
46
runcmd "ruby script/rails runner 'p Rails.application.config.assets.css_compressor'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'development' }
@@ -59,42 +51,24 @@ class SassRailsTest < Sass::Rails::TestCase
59
51
test 'sass defines compressor by default in test mode' do
60
52
within_rails_app 'scss_project' do
61
53
runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'test' }
62
- assert_output /Sass::Rails::CssCompressor/
54
+ assert_equal 'sass' , $last_ouput . chomp
63
55
end
64
56
end
65
57
66
58
test 'sass defines compressor by default in production mode' do
67
59
within_rails_app 'scss_project' do
68
60
runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'" , Dir . pwd , true , 'Gemfile' , { 'RAILS_ENV' => 'production' }
69
- assert_output /Sass::Rails::CssCompressor/
61
+ assert_equal 'sass' , $last_ouput . chomp
70
62
end
71
63
end
72
64
73
- # This tests both the railtie responsible for passing in the :compact style, and the compressor for honoring it
74
- test "compressor outputs compact style when specified in config" do
75
- command = <<END_OF_COMMAND
76
- puts Rails.application.config.assets.css_compressor.compress(<<CSS)
77
- div {
78
- color: red;
79
- }
80
- span {
81
- color: blue;
82
- }
83
- CSS
84
- END_OF_COMMAND
85
- within_rails_app "alternate_config_project" do
86
- runcmd "ruby script/rails runner '#{ command } '" , Dir . pwd , true , "Gemfile" , { "RAILS_ENV" => "test" }
87
- assert_line_count 3
88
- end
89
- end
90
-
91
- test "sprockets require works correctly" do
92
- css_output = sprockets_render ( "scss_project" , "css_application.css" )
65
+ test 'sprockets require works correctly' do
66
+ css_output = sprockets_render ( 'scss_project' , 'css_application.css' )
93
67
assert_match /globbed/ , css_output
94
68
end
95
69
96
- test " sass imports work correctly" do
97
- css_output = sprockets_render ( " scss_project" , " application.css.scss" )
70
+ test ' sass imports work correctly' do
71
+ css_output = sprockets_render ( ' scss_project' , ' application.css.scss' )
98
72
assert_match /main/ , css_output
99
73
assert_match /top-level/ , css_output
100
74
assert_match /partial-sass/ , css_output
@@ -109,8 +83,8 @@ class SassRailsTest < Sass::Rails::TestCase
109
83
assert_match /without-css-ext/ , css_output
110
84
end
111
85
112
- test " sass asset paths work" do
113
- css_output = sprockets_render ( " scss_project" , " application.css.scss" )
86
+ test ' sass asset paths work' do
87
+ css_output = sprockets_render ( ' scss_project' , ' application.css.scss' )
114
88
assert_match %r{asset-path:\s *"/assets/rails.png"} , css_output , 'asset-path:\s*"/assets/rails.png"'
115
89
assert_match %r{asset-url:\s *url\( /assets/rails.png\) } , css_output , 'asset-url:\s*url\(/assets/rails.png\)'
116
90
assert_match %r{image-path:\s *"/assets/rails.png"} , css_output , 'image-path:\s*"/assets/rails.png"'
@@ -130,15 +104,7 @@ class SassRailsTest < Sass::Rails::TestCase
130
104
asset_data_url_regexp = %r{asset-data-url:\s *url\( (.*?)\) }
131
105
assert_match asset_data_url_regexp , css_output , 'asset-data-url:\s*url\((.*?)\)'
132
106
asset_data_url_match = css_output . match ( asset_data_url_regexp ) [ 1 ]
133
- asset_data_url_expected = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUl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S4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE3MzcyNTQ2RDY2QjExRTA5RTMzQTlDQTZFODJBQTFCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D'
134
108
assert_equal asset_data_url_expected , asset_data_url_match
135
109
end
136
-
137
- test "css compressor compresses" do
138
- assert_equal "div{color:red}\n " , Sass ::Rails ::CssCompressor . new . compress ( <<CSS )
139
- div {
140
- color: red;
141
- }
142
- CSS
143
- end
144
110
end
0 commit comments