2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2010-03-15 22:20:55 -04:00
|
|
|
|
|
|
|
begin
|
2009-05-02 08:49:43 -04:00
|
|
|
require 'sass'
|
2008-12-13 16:06:02 -05:00
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class SassTest < Minitest::Test
|
2010-09-19 11:57:48 -04:00
|
|
|
def sass_app(options = {}, &block)
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2020-03-13 17:20:04 -04:00
|
|
|
set :views, __dir__ + '/views'
|
2010-09-19 11:57:48 -04:00
|
|
|
set options
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
|
|
|
end
|
2008-12-13 16:06:02 -05:00
|
|
|
get '/'
|
2008-04-08 20:51:20 -04:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
it 'renders inline Sass strings' do
|
2018-02-19 11:17:50 -05:00
|
|
|
sass_app { sass "#sass\n background-color: white\n" }
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass {\n background-color: white; }\n", body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2010-09-19 11:57:48 -04:00
|
|
|
it 'defaults content type to css' do
|
2018-02-19 11:17:50 -05:00
|
|
|
sass_app { sass "#sass\n background-color: white\n" }
|
2010-09-19 11:57:48 -04:00
|
|
|
assert ok?
|
|
|
|
assert_equal "text/css;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type per route' do
|
|
|
|
sass_app do
|
|
|
|
content_type :html
|
2018-02-19 11:17:50 -05:00
|
|
|
sass "#sass\n background-color: white\n"
|
2010-09-19 11:57:48 -04:00
|
|
|
end
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type globally' do
|
2012-05-21 17:21:59 -04:00
|
|
|
sass_app(:sass => { :content_type => 'html' }) {
|
2018-02-19 11:17:50 -05:00
|
|
|
sass "#sass\n background-color: white\n"
|
2012-05-21 17:21:59 -04:00
|
|
|
}
|
2010-09-19 11:57:48 -04:00
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
it 'renders .sass files in views path' do
|
|
|
|
sass_app { sass :hello }
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass {\n background-color: white; }\n", body
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
it 'ignores the layout option' do
|
|
|
|
sass_app { sass :hello, :layout => :layout2 }
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass {\n background-color: white; }\n", body
|
2008-04-08 20:51:20 -04:00
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
it "raises error if template not found" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { sass :no_such_template } }
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2008-12-13 16:06:02 -05:00
|
|
|
end
|
2009-03-14 22:10:55 -04:00
|
|
|
|
|
|
|
it "passes SASS options to the Sass engine" do
|
2012-05-21 17:21:59 -04:00
|
|
|
sass_app do
|
|
|
|
sass(
|
2018-02-19 11:48:07 -05:00
|
|
|
"#sass\n background-color: white\n color: black\n",
|
2010-05-12 01:11:05 -04:00
|
|
|
:style => :compact
|
2012-05-21 17:21:59 -04:00
|
|
|
)
|
|
|
|
end
|
2009-03-31 01:04:54 -04:00
|
|
|
assert ok?
|
2012-05-21 17:21:59 -04:00
|
|
|
assert_equal("#sass { background-color: white; color: black; }\n", body)
|
2009-03-31 01:04:54 -04:00
|
|
|
end
|
|
|
|
|
2009-03-14 22:10:55 -04:00
|
|
|
it "passes default SASS options to the Sass engine" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2009-03-27 13:00:33 -04:00
|
|
|
set :sass, {:style => :compact} # default Sass style is :nested
|
2018-02-19 11:48:07 -05:00
|
|
|
get('/') { sass("#sass\n background-color: white\n color: black\n") }
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-03-14 22:10:55 -04:00
|
|
|
get '/'
|
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass { background-color: white; color: black; }\n", body
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
|
2010-05-12 01:11:05 -04:00
|
|
|
it "merges the default SASS options with the overrides" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2010-05-12 01:11:05 -04:00
|
|
|
# default Sass attribute_syntax is :normal (with : in front)
|
|
|
|
set :sass, {:style => :compact, :attribute_syntax => :alternate }
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') { sass("#sass\n background-color: white\n color: black\n") }
|
|
|
|
get('/raised') do
|
2010-05-12 01:11:05 -04:00
|
|
|
# retains global attribute_syntax settings
|
2012-05-21 17:21:59 -04:00
|
|
|
sass(
|
|
|
|
"#sass\n :background-color white\n :color black\n",
|
2010-05-12 01:11:05 -04:00
|
|
|
:style => :expanded
|
2012-05-21 17:21:59 -04:00
|
|
|
)
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/expanded_normal') do
|
|
|
|
sass(
|
|
|
|
"#sass\n :background-color white\n :color black\n",
|
2010-05-12 01:11:05 -04:00
|
|
|
:style => :expanded, :attribute_syntax => :normal
|
2012-05-21 17:21:59 -04:00
|
|
|
)
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
2012-05-21 17:21:59 -04:00
|
|
|
end
|
2009-03-14 22:10:55 -04:00
|
|
|
get '/'
|
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass { background-color: white; color: black; }\n", body
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Sass::SyntaxError) { get('/raised') }
|
2009-03-14 22:10:55 -04:00
|
|
|
get '/expanded_normal'
|
|
|
|
assert ok?
|
2010-05-12 01:11:05 -04:00
|
|
|
assert_equal "#sass {\n background-color: white;\n color: black;\n}\n",
|
|
|
|
body
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
2008-04-08 20:51:20 -04:00
|
|
|
end
|
2010-03-15 22:20:55 -04:00
|
|
|
|
2011-01-25 03:27:15 -05:00
|
|
|
rescue LoadError
|
2017-06-25 05:19:22 -04:00
|
|
|
warn "#{$!}: skipping sass tests"
|
2010-03-15 22:20:55 -04:00
|
|
|
end
|