2009-01-13 12:53:53 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
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
|
2008-12-13 16:06:02 -05:00
|
|
|
def sass_app(&block)
|
|
|
|
mock_app {
|
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
|
|
|
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
|
|
|
|
sass_app { sass "#sass\n :background-color #FFF\n" }
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass {\n background-color: #FFF; }\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 'renders .sass files in views path' do
|
|
|
|
sass_app { sass :hello }
|
2009-01-14 17:00:26 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass {\n background-color: #FFF; }\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?
|
|
|
|
assert_equal "#sass {\n background-color: #FFF; }\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 {
|
2009-03-27 13:00:33 -04:00
|
|
|
sass "#sass\n :background-color #FFF\n :color #000\n", :style => :compact
|
2009-03-31 01:04:54 -04:00
|
|
|
}
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
|
|
|
|
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
|
|
|
|
sass "#sass\n :background-color #FFF\n :color #000\n"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "merges the default SASS options with the overrides and passes them to the Sass engine" do
|
|
|
|
mock_app {
|
|
|
|
set :sass, {:style => :compact, :attribute_syntax => :alternate } # default Sass attribute_syntax is :normal (with : in front)
|
|
|
|
get '/' do
|
|
|
|
sass "#sass\n background-color: #FFF\n color: #000\n"
|
|
|
|
end
|
|
|
|
get '/raised' do
|
2009-03-27 13:00:33 -04:00
|
|
|
sass "#sass\n :background-color #FFF\n :color #000\n", :style => :expanded # retains global attribute_syntax settings
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
get '/expanded_normal' do
|
2009-03-27 13:00:33 -04:00
|
|
|
sass "#sass\n :background-color #FFF\n :color #000\n", :style => :expanded, :attribute_syntax => :normal
|
2009-03-14 22:10:55 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass { background-color: #FFF; color: #000; }\n", body
|
|
|
|
assert_raise(Sass::SyntaxError) { get('/raised') }
|
|
|
|
get '/expanded_normal'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#sass {\n background-color: #FFF;\n color: #000;\n}\n", body
|
|
|
|
end
|
2008-04-08 20:51:20 -04:00
|
|
|
end
|