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
|
|
|
|
2009-03-26 11:42:13 -04:00
|
|
|
class SassTest < Test::Unit::TestCase
|
2010-09-19 11:57:48 -04:00
|
|
|
def sass_app(options = {}, &block)
|
2008-12-13 16:06:02 -05:00
|
|
|
mock_app {
|
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
2010-09-19 11:57:48 -04:00
|
|
|
set options
|
2008-12-13 16:06:02 -05:00
|
|
|
get '/', &block
|
|
|
|
}
|
|
|
|
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
|
2010-05-12 01:11:05 -04: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
|
|
|
|
sass_app { sass "#sass\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
|
|
|
|
sass_app do
|
|
|
|
content_type :html
|
|
|
|
sass "#sass\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
|
|
|
|
sass_app(:sass => { :content_type => 'html' }) do
|
|
|
|
sass "#sass\n :background-color white\n"
|
|
|
|
end
|
|
|
|
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
|
|
|
|
mock_app {
|
|
|
|
get('/') { sass :no_such_template }
|
|
|
|
}
|
2009-01-14 17:00:26 -05:00
|
|
|
assert_raise(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
|
|
|
|
sass_app {
|
2010-05-12 01:11:05 -04:00
|
|
|
sass "#sass\n :background-color white\n :color black\n",
|
|
|
|
:style => :compact
|
2009-03-31 01:04:54 -04:00
|
|
|
}
|
|
|
|
assert ok?
|
2010-05-12 01:11:05 -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
|
|
|
|
mock_app {
|
2009-03-27 13:00:33 -04:00
|
|
|
set :sass, {:style => :compact} # default Sass style is :nested
|
2009-03-14 22:10:55 -04:00
|
|
|
get '/' do
|
2010-05-12 01:11:05 -04:00
|
|
|
sass "#sass\n :background-color white\n :color black\n"
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
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
|
2009-03-14 22:10:55 -04:00
|
|
|
mock_app {
|
2010-05-12 01:11:05 -04:00
|
|
|
# default Sass attribute_syntax is :normal (with : in front)
|
|
|
|
set :sass, {:style => :compact, :attribute_syntax => :alternate }
|
2009-03-14 22:10:55 -04:00
|
|
|
get '/' do
|
2010-05-12 01:11:05 -04:00
|
|
|
sass "#sass\n background-color: white\n color: black\n"
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
get '/raised' do
|
2010-05-12 01:11:05 -04:00
|
|
|
# retains global attribute_syntax settings
|
|
|
|
sass "#sass\n :background-color white\n :color black\n",
|
|
|
|
:style => :expanded
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
get '/expanded_normal' do
|
2010-05-12 01:11:05 -04:00
|
|
|
sass "#sass\n :background-color white\n :color black\n",
|
|
|
|
:style => :expanded, :attribute_syntax => :normal
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
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
|
|
|
assert_raise(Sass::SyntaxError) { get('/raised') }
|
|
|
|
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
|
2010-03-15 22:20:55 -04:00
|
|
|
warn "#{$!.to_s}: skipping sass tests"
|
|
|
|
end
|