require 'test/spec'
require 'sinatra/base'
require 'sinatra/test'
describe "ERB Templates" do
include Sinatra::Test
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 %>' }
should.be.ok
body.should.equal '2'
it 'renders .erb files in views path' do
erb_app { erb :hello }
body.should.equal "Hello World\n"
it 'takes a :locals option' do
erb_app {
locals = {:foo => 'Bar'}
erb '<%= foo %>', :locals => locals
body.should.equal 'Bar'
it "renders with inline layouts" do
layout { 'THIS. IS. <%= yield.upcase %>!' }
get('/') { erb 'Sparta' }
body.should.equal 'THIS. IS. SPARTA!'
it "renders with file layouts" do
erb 'Hello World', :layout => :layout2
body.should.equal "ERB Layout!\nHello World\n"