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'
|
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class LessTest < Minitest::Test
|
2010-09-19 11:57:48 -04:00
|
|
|
def less_app(options = {}, &block)
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2010-03-01 07:13:10 -05:00
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
2010-09-19 11:57:48 -04:00
|
|
|
set options
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
|
|
|
end
|
2010-03-01 07:13:10 -05:00
|
|
|
get '/'
|
|
|
|
end
|
2010-03-01 19:07:57 -05:00
|
|
|
|
2010-03-01 07:13:10 -05:00
|
|
|
it 'renders inline Less strings' do
|
2012-05-21 17:21:59 -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
|
2012-05-21 17:21:59 -04:00
|
|
|
less_app {
|
|
|
|
less "@white_color: #fff; #main { background-color: @white_color }"
|
|
|
|
}
|
2010-09-19 11:57:48 -04:00
|
|
|
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
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app { get('/') { less :no_such_template } }
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2010-03-01 07:13:10 -05:00
|
|
|
end
|
|
|
|
end
|
2011-01-25 03:27:15 -05:00
|
|
|
|
|
|
|
rescue LoadError
|
2017-06-25 05:19:22 -04:00
|
|
|
warn "#{$!}: skipping less tests"
|
2011-01-25 03:27:15 -05:00
|
|
|
end
|