2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2011-01-25 03:27:15 -05:00
|
|
|
|
|
|
|
begin
|
2010-03-01 07:13:10 -05:00
|
|
|
require 'less'
|
|
|
|
|
|
|
|
class LessTest < Test::Unit::TestCase
|
2010-09-19 11:57:48 -04:00
|
|
|
def less_app(options = {}, &block)
|
2010-03-01 07:13:10 -05:00
|
|
|
mock_app {
|
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
2010-09-19 11:57:48 -04:00
|
|
|
set options
|
2010-03-01 07:13:10 -05:00
|
|
|
get '/', &block
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
end
|
2010-03-01 19:07:57 -05:00
|
|
|
|
2010-03-01 07:13:10 -05:00
|
|
|
it 'renders inline Less strings' do
|
2010-09-19 11:57:48 -04:00
|
|
|
less_app { less "@white_color: #fff; #main { background-color: @white_color }" }
|
2010-03-01 07:13:10 -05:00
|
|
|
assert ok?
|
2011-10-07 00:47:06 -04:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 07:13:10 -05:00
|
|
|
end
|
2010-03-01 19:07:57 -05:00
|
|
|
|
2010-09-19 11:57:48 -04:00
|
|
|
it 'defaults content type to css' do
|
|
|
|
less_app { less "@white_color: #fff; #main { background-color: @white_color }" }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/css;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type per route' do
|
|
|
|
less_app do
|
|
|
|
content_type :html
|
|
|
|
less "@white_color: #fff; #main { background-color: @white_color }"
|
|
|
|
end
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults allows setting content type globally' do
|
|
|
|
less_app(:less => { :content_type => 'html' }) do
|
|
|
|
less "@white_color: #fff; #main { background-color: @white_color }"
|
|
|
|
end
|
|
|
|
assert ok?
|
|
|
|
assert_equal "text/html;charset=utf-8", response['Content-Type']
|
|
|
|
end
|
|
|
|
|
2010-03-01 07:13:10 -05:00
|
|
|
it 'renders .less files in views path' do
|
|
|
|
less_app { less :hello }
|
|
|
|
assert ok?
|
2011-10-07 00:47:06 -04:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 07:13:10 -05:00
|
|
|
end
|
2010-03-01 19:07:57 -05:00
|
|
|
|
2010-03-01 07:13:10 -05:00
|
|
|
it 'ignores the layout option' do
|
|
|
|
less_app { less :hello, :layout => :layout2 }
|
|
|
|
assert ok?
|
2011-10-07 00:47:06 -04:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 07:13:10 -05:00
|
|
|
end
|
2010-03-01 19:07:57 -05:00
|
|
|
|
2010-03-01 07:13:10 -05:00
|
|
|
it "raises error if template not found" do
|
|
|
|
mock_app {
|
|
|
|
get('/') { less :no_such_template }
|
|
|
|
}
|
|
|
|
assert_raise(Errno::ENOENT) { get('/') }
|
|
|
|
end
|
|
|
|
end
|
2011-01-25 03:27:15 -05:00
|
|
|
|
|
|
|
rescue LoadError
|
|
|
|
warn "#{$!.to_s}: skipping less tests"
|
|
|
|
end
|