2011-05-11 09:44:02 +02:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2011-01-25 00:27:15 -08:00
|
|
|
|
|
|
|
begin
|
2010-03-01 14:13:10 +02:00
|
|
|
require 'less'
|
|
|
|
|
2015-01-11 01:00:47 +05:30
|
|
|
class LessTest < Minitest::Test
|
2010-09-19 17:57:48 +02:00
|
|
|
def less_app(options = {}, &block)
|
2012-05-21 17:21:59 -04:00
|
|
|
mock_app do
|
2020-03-13 22:20:04 +01:00
|
|
|
set :views, __dir__ + '/views'
|
2010-09-19 17:57:48 +02:00
|
|
|
set options
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
|
|
|
end
|
2010-03-01 14:13:10 +02:00
|
|
|
get '/'
|
|
|
|
end
|
2010-03-01 16:07:57 -08:00
|
|
|
|
2010-03-01 14:13:10 +02: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 14:13:10 +02:00
|
|
|
assert ok?
|
2011-10-06 21:47:06 -07:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 14:13:10 +02:00
|
|
|
end
|
2010-03-01 16:07:57 -08:00
|
|
|
|
2010-09-19 17:57:48 +02: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 17:57:48 +02: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 14:13:10 +02:00
|
|
|
it 'renders .less files in views path' do
|
|
|
|
less_app { less :hello }
|
|
|
|
assert ok?
|
2011-10-06 21:47:06 -07:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 14:13:10 +02:00
|
|
|
end
|
2010-03-01 16:07:57 -08:00
|
|
|
|
2010-03-01 14:13:10 +02:00
|
|
|
it 'ignores the layout option' do
|
|
|
|
less_app { less :hello, :layout => :layout2 }
|
|
|
|
assert ok?
|
2011-10-06 21:47:06 -07:00
|
|
|
assert_equal "#main{background-color:#ffffff;}", body.gsub(/\s/, "")
|
2010-03-01 14:13:10 +02:00
|
|
|
end
|
2010-03-01 16:07:57 -08:00
|
|
|
|
2010-03-01 14:13:10 +02: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-11 01:00:47 +05:30
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2010-03-01 14:13:10 +02:00
|
|
|
end
|
|
|
|
end
|
2011-01-25 00:27:15 -08:00
|
|
|
|
|
|
|
rescue LoadError
|
2017-06-25 11:19:22 +02:00
|
|
|
warn "#{$!}: skipping less tests"
|
2011-01-25 00:27:15 -08:00
|
|
|
end
|