require File.dirname(__FILE__) + '/test_helper' class SinatraMarukuTest < Test::Unit::TestCase include Rack::Test::Methods def maruku_app(&block) mock_app { set :views, File.dirname(__FILE__) + '/views' helpers Sinatra::Maruku set :show_exceptions, false get '/', &block } get '/' end def test_renders_inline_strings maruku_app { maruku 'hello world' } assert last_response.ok? assert_equal "

hello world

", last_response.body end def test_renders_inline_erb_string maruku_app { maruku '<%= 1 + 1 %>' } assert last_response.ok? assert_equal "

2

", last_response.body end def test_renders_files_in_views_path maruku_app { maruku :hello } assert last_response.ok? assert_equal "

hello world

", last_response.body end def test_takes_locals_option maruku_app { locals = {:foo => 'Bar'} maruku "<%= foo %>", :locals => locals } assert last_response.ok? assert_equal "

Bar

", last_response.body end def test_renders_with_inline_layouts maruku_app { maruku 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>' } assert last_response.ok? assert_equal "\n\n\n\n\n

THIS. IS.

SPARTA

\n", last_response.body end def test_renders_with_file_layouts maruku_app { maruku 'hello world', :layout => :layout2 } assert last_response.ok? assert_equal "\n\n\n\n\n

erb layout

hello world

\n", last_response.body end def test_renders_erb_with_blocks mock_app { set :views, File.dirname(__FILE__) + '/views' helpers Sinatra::Maruku def container yield end def is "THIS. IS. SPARTA!" end get '/' do maruku '<% container do %> <%= is %> <% end %>' end } get '/' assert last_response.ok? assert_equal "

THIS. IS. SPARTA!

", last_response.body end def test_raises_error_if_template_not_found mock_app { set :views, File.dirname(__FILE__) + '/views' helpers Sinatra::Maruku set :show_exceptions, false get('/') { maruku :no_such_template } } assert_raise(Errno::ENOENT) { get('/') } end end