2011-05-11 03:44:02 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2010-09-12 11:00:33 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'markaby'
|
|
|
|
|
2015-01-10 14:30:47 -05:00
|
|
|
class MarkabyTest < Minitest::Test
|
2010-09-12 11:00:33 -04:00
|
|
|
def markaby_app(&block)
|
|
|
|
mock_app do
|
2020-03-13 17:20:04 -04:00
|
|
|
set :views, __dir__ + '/views'
|
2012-05-21 17:21:59 -04:00
|
|
|
get('/', &block)
|
2010-09-12 11:00:33 -04:00
|
|
|
end
|
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders inline markaby strings' do
|
|
|
|
markaby_app { markaby 'h1 "Hiya"' }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Hiya</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders .markaby files in views path' do
|
|
|
|
markaby_app { markaby :hello }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Hello From Markaby</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders with inline layouts" do
|
|
|
|
mock_app do
|
|
|
|
layout { 'h1 { text "THIS. IS. "; yield }' }
|
|
|
|
get('/') { markaby 'em "SPARTA"' }
|
|
|
|
end
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders with file layouts" do
|
|
|
|
markaby_app { markaby 'text "Hello World"', :layout => :layout2 }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
|
|
|
|
end
|
|
|
|
|
2010-11-12 15:18:52 -05:00
|
|
|
it 'renders inline markaby blocks' do
|
2010-12-24 10:02:07 -05:00
|
|
|
markaby_app { markaby { h1 'Hiya' } }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Hiya</h1>", body
|
2010-11-12 15:18:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders inline markaby blocks with inline layouts' do
|
2010-12-24 10:02:07 -05:00
|
|
|
markaby_app do
|
|
|
|
settings.layout { 'h1 { text "THIS. IS. "; yield }' }
|
|
|
|
markaby { em 'SPARTA' }
|
2010-11-12 15:18:52 -05:00
|
|
|
end
|
2010-12-24 10:02:07 -05:00
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>THIS. IS. <em>SPARTA</em></h1>", body
|
2010-11-12 15:18:52 -05:00
|
|
|
end
|
|
|
|
|
2012-07-18 15:07:24 -04:00
|
|
|
it 'renders inline markaby blocks with file layouts' do
|
2010-12-24 10:02:07 -05:00
|
|
|
markaby_app { markaby(:layout => :layout2) { text "Hello World" } }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Markaby Layout!</h1><p>Hello World</p>", body
|
2010-11-12 15:18:52 -05:00
|
|
|
end
|
|
|
|
|
2010-09-12 11:00:33 -04:00
|
|
|
it "raises error if template not found" do
|
|
|
|
mock_app { get('/') { markaby :no_such_template } }
|
2015-01-10 14:30:47 -05:00
|
|
|
assert_raises(Errno::ENOENT) { get('/') }
|
2010-09-12 11:00:33 -04:00
|
|
|
end
|
2012-07-18 15:07:24 -04:00
|
|
|
|
2010-09-12 11:00:33 -04:00
|
|
|
it "allows passing locals" do
|
2012-05-21 17:21:59 -04:00
|
|
|
markaby_app {
|
2010-09-12 11:00:33 -04:00
|
|
|
markaby 'text value', :locals => { :value => 'foo' }
|
2012-05-21 17:21:59 -04:00
|
|
|
}
|
2010-09-12 11:00:33 -04:00
|
|
|
assert ok?
|
|
|
|
assert_equal 'foo', body
|
|
|
|
end
|
|
|
|
end
|
2011-01-25 03:27:15 -05:00
|
|
|
|
|
|
|
rescue LoadError
|
2017-06-25 05:19:22 -04:00
|
|
|
warn "#{$!}: skipping markaby tests"
|
2010-09-12 11:00:33 -04:00
|
|
|
end
|