test/templates_test.rb in bmizerany-sinatra-0.8.10 vs test/templates_test.rb in bmizerany-sinatra-0.9.0

- old
+ new

@@ -1,8 +1,12 @@ -require File.dirname(__FILE__) + '/helper' +require 'test/spec' +require 'sinatra/base' +require 'sinatra/test' describe 'Templating' do + include Sinatra::Test + def render_app(&block) mock_app { def render_test(template, data, options, &block) inner = block ? block.call : '' data + inner @@ -22,59 +26,51 @@ File.unlink(layout) rescue nil end it 'renders String templates directly' do render_app { render :test, 'Hello World' } - assert ok? - assert_equal 'Hello World', body + should.be.ok + body.should.equal 'Hello World' end it 'renders Proc templates using the call result' do render_app { render :test, Proc.new {'Hello World'} } - assert ok? - assert_equal 'Hello World', body + should.be.ok + body.should.equal 'Hello World' end it 'looks up Symbol templates in views directory' do render_app { render :test, :hello } - assert ok? - assert_equal "Hello World!\n", body + should.be.ok + body.should.equal "Hello World!\n" end it 'uses the default layout template if not explicitly overridden' do with_default_layout do render_app { render :test, :hello } - assert ok? - assert_equal "Layout!\nHello World!\n", body + should.be.ok + body.should.equal "Layout!\nHello World!\n" end end - it 'uses the default layout template if not really overriden' do - with_default_layout do - render_app { render :test, :hello, :layout => true } - assert ok? - assert_equal "Layout!\nHello World!\n", body - end - end - it 'uses the layout template specified' do render_app { render :test, :hello, :layout => :layout2 } - assert ok? - assert_equal "Layout 2!\nHello World!\n", body + should.be.ok + body.should.equal "Layout 2!\nHello World!\n" end it 'uses layout templates defined with the #template method' do render_app { render :test, :hello, :layout => :layout3 } - assert ok? - assert_equal "Layout 3!\nHello World!\n", body + should.be.ok + body.should.equal "Layout 3!\nHello World!\n" end it 'loads templates from source file with use_in_file_templates!' do mock_app { use_in_file_templates! } - assert_equal "this is foo\n\n", @app.templates[:foo] - assert_equal "X\n= yield\nX\n", @app.templates[:layout] + @app.templates[:foo].should.equal "this is foo\n\n" + @app.templates[:layout].should.equal "X\n= yield\nX\n" end end __END__