test/erb_test.rb in Syd-sinatra-0.3.2 vs test/erb_test.rb in Syd-sinatra-0.9.0.2
- old
+ new
@@ -1,136 +1,50 @@
require File.dirname(__FILE__) + '/helper'
-context "Erb" do
+describe "ERB Templates" do
+ def erb_app(&block)
+ mock_app {
+ set :views, File.dirname(__FILE__) + '/views'
+ get '/', &block
+ }
+ get '/'
+ end
- setup do
- Sinatra.application = nil
+ it 'renders inline ERB strings' do
+ erb_app { erb '<%= 1 + 1 %>' }
+ assert ok?
+ assert_equal '2', body
end
- context "without layouts" do
-
- setup do
- Sinatra.application = nil
- end
-
- specify "should render" do
-
- get '/no_layout' do
- erb '<%= 1 + 1 %>'
- end
-
- get_it '/no_layout'
- should.be.ok
- body.should == '2'
-
- end
-
- specify "should take an options hash with :locals set with a string" do
- get '/locals' do
- erb '<%= foo %>', :locals => {:foo => "Bar"}
- end
-
- get_it '/locals'
- should.be.ok
- body.should == 'Bar'
- end
-
- specify "should take an options hash with :locals set with a complex object" do
- get '/locals-complex' do
- erb '<%= foo[0] %>', :locals => {:foo => ["foo", "bar", "baz"]}
- end
-
- get_it '/locals-complex'
- should.be.ok
- body.should == 'foo'
- end
+ it 'renders .erb files in views path' do
+ erb_app { erb :hello }
+ assert ok?
+ assert_equal "Hello World\n", body
end
- context "with layouts" do
-
- setup do
- Sinatra.application = nil
- end
-
- specify "can be inline" do
-
- layout do
- %Q{This is <%= yield %>!}
- end
-
- get '/lay' do
- erb 'Blake'
- end
-
- get_it '/lay'
- should.be.ok
- body.should.equal 'This is Blake!'
-
- end
-
- specify "can use named layouts" do
-
- layout :pretty do
- %Q{<h1><%= yield %></h1>}
- end
-
- get '/pretty' do
- erb 'Foo', :layout => :pretty
- end
-
- get '/not_pretty' do
- erb 'Bar'
- end
-
- get_it '/pretty'
- body.should.equal '<h1>Foo</h1>'
-
- get_it '/not_pretty'
- body.should.equal 'Bar'
-
- end
-
- specify "can be read from a file if they're not inlined" do
-
- get '/foo' do
- @title = 'Welcome to the Hello Program'
- erb 'Blake', :layout => :foo_layout,
- :views_directory => File.dirname(__FILE__) + "/views"
- end
-
- get_it '/foo'
- body.should.equal "Welcome to the Hello Program\nHi Blake\n"
-
- end
-
+ it 'takes a :locals option' do
+ erb_app {
+ locals = {:foo => 'Bar'}
+ erb '<%= foo %>', :locals => locals
+ }
+ assert ok?
+ assert_equal 'Bar', body
end
- context "Templates (in general)" do
-
- specify "are read from files if Symbols" do
-
- get '/from_file' do
- @name = 'Alena'
- erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
- end
-
- get_it '/from_file'
-
- body.should.equal 'You rock Alena!'
-
- end
-
- specify "use layout.ext by default if available" do
-
- get '/layout_from_file' do
- erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
- end
-
- get_it '/layout_from_file'
- should.be.ok
- body.should.equal "x This is foo! x \n"
-
- end
-
+ it "renders with inline layouts" do
+ mock_app {
+ layout { 'THIS. IS. <%= yield.upcase %>!' }
+ get('/') { erb 'Sparta' }
+ }
+ get '/'
+ assert ok?
+ assert_equal 'THIS. IS. SPARTA!', body
end
+ it "renders with file layouts" do
+ erb_app {
+ erb 'Hello World', :layout => :layout2
+ }
+ assert ok?
+ assert_equal "ERB Layout!\nHello World\n", body
+ end
end