Permalink
Browse files

First pass at block styles for tests

TODO:
* test/routing_test.rb
* test/settings_test.rb
  • Loading branch information...
1 parent cab56ed commit 46e8bd67b3503b0a86530aac8cb2be26e2d100be @zzak zzak committed May 21, 2012
View
@@ -7,9 +7,7 @@ def test_default
describe 'Sinatra::Base subclasses' do
class TestApp < Sinatra::Base
- get '/' do
- 'Hello World'
- end
+ get('/') { 'Hello World' }
end
it 'include Rack::Utils' do
@@ -99,9 +97,7 @@ def route_missing
super
end
- get '/' do
- 'Hello from middleware'
- end
+ get('/') { 'Hello from middleware' }
end
middleware = TestMiddleware.new(app)
@@ -125,9 +121,7 @@ def route_missing
end
class TestMiddleware < Sinatra::Base
- get '/low-level-forward' do
- app.call(env)
- end
+ get('/low-level-forward') { app.call(env) }
end
it 'can call the downstream app directly and return result' do
View
@@ -5,11 +5,11 @@
class BuilderTest < Test::Unit::TestCase
def builder_app(options = {}, &block)
- mock_app {
+ mock_app do
set :views, File.dirname(__FILE__) + '/views'
set options
- get '/', &block
- }
+ get('/', &block)
+ end
get '/'
end
@@ -43,49 +43,45 @@ def builder_app(options = {}, &block)
end
it 'renders inline blocks' do
- builder_app {
+ builder_app do
@name = "Frank & Mary"
- builder do |xml|
- xml.couple @name
- end
- }
+ builder { |xml| xml.couple @name }
+ end
assert ok?
assert_equal "<couple>Frank &amp; Mary</couple>\n", body
end
it 'renders .builder files in views path' do
- builder_app {
+ builder_app do
@name = "Blue"
builder :hello
- }
+ end
assert ok?
assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
end
it "renders with inline layouts" do
- mock_app {
- layout do
- %(xml.layout { xml << yield })
- end
+ mock_app do
+ layout { %(xml.layout { xml << yield }) }
get('/') { builder %(xml.em 'Hello World') }
- }
+ end
get '/'
assert ok?
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
end
it "renders with file layouts" do
- builder_app {
+ builder_app do
builder %(xml.em 'Hello World'), :layout => :layout2
- }
+ end
assert ok?
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
end
it "raises error if template not found" do
- mock_app {
+ mock_app do
get('/') { builder :no_such_template }
- }
+ end
assert_raise(Errno::ENOENT) { get('/') }
end
end
View
@@ -12,11 +12,11 @@
class CoffeeTest < Test::Unit::TestCase
def coffee_app(options = {}, &block)
- mock_app {
+ mock_app do
set :views, File.dirname(__FILE__) + '/views'
set(options)
- get '/', &block
- }
+ get('/', &block)
+ end
get '/'
end
@@ -77,9 +77,7 @@ def coffee_app(options = {}, &block)
it "passes default coffee options to the coffee engine" do
mock_app do
set :coffee, :no_wrap => true # default coffee style is :nested
- get '/' do
- coffee "alert 'Aye!'\n"
- end
+ get('/') { coffee "alert 'Aye!'\n" }
end
get '/'
assert ok?
View
@@ -7,7 +7,7 @@ class CreoleTest < Test::Unit::TestCase
def creole_app(&block)
mock_app do
set :views, File.dirname(__FILE__) + '/views'
- get '/', &block
+ get('/', &block)
end
get '/'
end
@@ -40,7 +40,9 @@ def creole_app(&block)
end
it "renders with file layouts" do
- creole_app { creole 'Hello World', :layout => :layout2, :layout_engine => :erb }
+ creole_app do
+ creole 'Hello World', :layout => :layout2, :layout_engine => :erb
+ end
assert ok?
assert_body "ERB Layout!\n<p>Hello World</p>"
end
@@ -49,9 +51,7 @@ def creole_app(&block)
mock_app do
template(:inner) { "hi" }
template(:outer) { "<outer><%= creole :inner %></outer>" }
- get '/' do
- erb :outer
- end
+ get('/') { erb :outer }
end
get '/'
@@ -63,9 +63,7 @@ def target
%w[get put post delete options patch].each do |verb|
it "delegates #{verb} correctly" do
delegation_app do
- send verb, '/hello' do
- 'Hello World'
- end
+ send(verb, '/hello') { 'Hello World' }
end
request = Rack::MockRequest.new(@app)
View
@@ -11,10 +11,10 @@ def setup
end
def erb_app(&block)
- mock_app {
+ mock_app do
set :views, File.dirname(__FILE__) + '/views'
- get '/', &block
- }
+ get('/', &block)
+ end
get '/'
end
@@ -35,57 +35,51 @@ def erb_app(&block)
end
it 'takes a :locals option' do
- erb_app {
+ erb_app do
locals = {:foo => 'Bar'}
erb '<%= foo %>', :locals => locals
- }
+ end
assert ok?
assert_equal 'Bar', body
end
it "renders with inline layouts" do
- mock_app {
+ mock_app do
layout { 'THIS. IS. <%= yield.upcase %>!' }
get('/') { erb 'Sparta' }
- }
+ end
get '/'
assert ok?
assert_equal 'THIS. IS. SPARTA!', body
end
it "renders with file layouts" do
- erb_app {
- erb 'Hello World', :layout => :layout2
- }
+ erb_app { erb 'Hello World', :layout => :layout2 }
assert ok?
assert_body "ERB Layout!\nHello World"
end
it "renders erb with blocks" do
- mock_app {
+ mock_app do
def container
@_out_buf << "THIS."
yield
@_out_buf << "SPARTA!"
end
def is; "IS." end
- get '/' do
- erb '<% container do %> <%= is %> <% end %>'
- end
- }
+ get('/') { erb '<% container do %> <%= is %> <% end %>' }
+ end
get '/'
assert ok?
assert_equal 'THIS. IS. SPARTA!', body
end
it "can be used in a nested fashion for partials and whatnot" do
- mock_app {
+ mock_app do
template(:inner) { "<inner><%= 'hi' %></inner>" }
template(:outer) { "<outer><%= erb :inner %></outer>" }
- get '/' do
- erb :outer
- end
- }
+ get('/') { erb :outer }
+ end
get '/'
assert ok?
@@ -42,9 +42,7 @@ def fizz!(name); end
end
it 'allows extending by passing a block' do
- Sinatra::Base.register {
- def im_in_ur_anonymous_module; end
- }
+ Sinatra::Base.register { def im_in_ur_anonymous_module; end }
assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
end
Oops, something went wrong.

0 comments on commit 46e8bd6

Please sign in to comment.