require File.dirname(__FILE__) + '/helper'
describe "ERB Templates" do
def erb_app(&block)
mock_app {
set :views, File.dirname(__FILE__) + '/views'
get '/', &block
}
get '/'
end
it 'renders inline ERB strings' do
erb_app { erb '<%= 1 + 1 %>' }
assert ok?
assert_equal '2', body
it 'renders .erb files in views path' do
erb_app { erb :hello }
assert_equal "Hello World\n", body
it 'takes a :locals option' do
erb_app {
locals = {:foo => 'Bar'}
erb '<%= foo %>', :locals => locals
assert_equal 'Bar', body
it "renders with inline layouts" do
layout { 'THIS. IS. <%= yield.upcase %>!' }
get('/') { erb 'Sparta' }
assert_equal 'THIS. IS. SPARTA!', body
it "renders with file layouts" do
erb 'Hello World', :layout => :layout2
assert_equal "ERB Layout!\nHello World\n", body