2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2010-08-29 20:56:44 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'sass'
|
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class ScssTest < Minitest::Test
|
2010-09-19 11:57:48 -04:00
|
|
|
def scss_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
|
2010-08-29 20:56:44 -04:00
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders inline Scss strings' do
|
|
|
|
scss_app { scss "#scss {\n background-color: white; }\n" }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#scss {\n background-color: white; }\n", body
|
|
|
|
end
|
|
|
|
|
2010-09-19 11:57:48 -04:00
|
|
|
it 'defaults content type to css' do
|
|
|
|
scss_app { scss "#scss {\n background-color: white; }\n" }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/css;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type per route' do
|
|
|
|
scss_app do
|
|
|
|
content_type :html
|
|
|
|
scss "#scss {\n background-color: white; }\n"
|
|
|
|
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
|
|
|
scss_app(:scss => { :content_type => 'html' }) {
|
2010-09-19 11:57:48 -04:00
|
|
|
scss "#scss {\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
|
|
|
|
|
2010-08-29 20:56:44 -04:00
|
|
|
it 'renders .scss files in views path' do
|
|
|
|
scss_app { scss :hello }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#scss {\n background-color: white; }\n", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores the layout option' do
|
|
|
|
scss_app { scss :hello, :layout => :layout2 }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#scss {\n background-color: white; }\n", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error if template not found" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { scss(:no_such_template) } }
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2010-08-29 20:56:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes scss options to the scss engine" do
|
2012-05-21 17:21:59 -04:00
|
|
|
scss_app do
|
|
|
|
scss(
|
|
|
|
"#scss {\n background-color: white;\n color: black\n}",
|
2010-08-29 20:56:44 -04:00
|
|
|
:style => :compact
|
2012-05-21 17:21:59 -04:00
|
|
|
)
|
|
|
|
end
|
2010-08-29 20:56:44 -04:00
|
|
|
assert ok?
|
|
|
|
assert_equal "#scss { background-color: white; color: black; }\n", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes default scss options to the scss engine" do
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2010-08-29 20:56:44 -04:00
|
|
|
set :scss, {:style => :compact} # default scss style is :nested
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/') {
|
2012-07-18 15:07:24 -04:00
|
|
|
scss("#scss {\n background-color: white;\n color: black;\n}")
|
2012-05-21 17:21:59 -04:00
|
|
|
}
|
2012-07-18 15:07:24 -04:00
|
|
|
end
|
2010-08-29 20:56:44 -04:00
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#scss { background-color: white; color: black; }\n", body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-25 03:27:15 -05:00
|
|
|
rescue LoadError
|
2017-06-25 05:19:22 -04:00
|
|
|
warn "#{$!}: skipping scss tests"
|
2010-08-29 20:56:44 -04:00
|
|
|
end
|