2009-01-13 12:53:53 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
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
|
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
|
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
|
|
|
|
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
|
|
|
|
|
|
|
rescue
|
|
|
|
warn "#{$!.to_s}: skipping sass tests"
|
|
|
|
end
|