Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #515 from zzak/block_styles

First pass at block styles for tests
  • Loading branch information...
commit 86749b747604c7005229fba2c0376f77e0ec10f3 2 parents cab56ed + 46e8bd6
@rkh rkh authored
Showing with 611 additions and 708 deletions.
  1. +3 −9 test/base_test.rb
  2. +15 −19 test/builder_test.rb
  3. +4 −6 test/coffee_test.rb
  4. +5 −5 test/creole_test.rb
  5. +1 −3 test/delegator_test.rb
  6. +14 −20 test/erb_test.rb
  7. +1 −3 test/extensions_test.rb
  8. +55 −57 test/filter_test.rb
  9. +16 −26 test/haml_test.rb
  10. +172 −210 test/helpers_test.rb
  11. +10 −8 test/less_test.rb
  12. +3 −3 test/liquid_test.rb
  13. +53 −83 test/mapped_error_test.rb
  14. +3 −3 test/markaby_test.rb
  15. +5 −5 test/markdown_test.rb
  16. +3 −3 test/middleware_test.rb
  17. +4 −6 test/nokogiri_test.rb
  18. +3 −3 test/radius_test.rb
  19. +5 −5 test/rdoc_test.rb
  20. +14 −30 test/readme_test.rb
  21. +1 −3 test/response_test.rb
  22. +11 −33 test/result_test.rb
  23. +8 −8 test/route_added_hook_test.rb
  24. +26 −26 test/sass_test.rb
  25. +16 −16 test/scss_test.rb
  26. +2 −2 test/server_test.rb
  27. +1 −6 test/sinatra_test.rb
  28. +11 −15 test/slim_test.rb
  29. +56 −15 test/static_test.rb
  30. +4 −2 test/streaming_test.rb
  31. +50 −45 test/templates_test.rb
  32. +9 −9 test/textile_test.rb
  33. +27 −21 test/yajl_test.rb
View
12 test/base_test.rb
@@ -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
34 test/builder_test.rb
@@ -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
10 test/coffee_test.rb
@@ -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
10 test/creole_test.rb
@@ -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 '/'
View
4 test/delegator_test.rb
@@ -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
34 test/erb_test.rb
@@ -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?
View
4 test/extensions_test.rb
@@ -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
View
112 test/filter_test.rb
@@ -5,14 +5,14 @@ class BeforeFilterTest < Test::Unit::TestCase
count = 0
mock_app do
get('/') { 'Hello World' }
- before {
+ before do
assert_equal 0, count
count = 1
- }
- before {
+ end
+ before do
assert_equal 1, count
count = 2
- }
+ end
end
get '/'
@@ -22,11 +22,11 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "can modify the request" do
- mock_app {
+ mock_app do
get('/foo') { 'foo' }
get('/bar') { 'bar' }
before { request.path_info = '/bar' }
- }
+ end
get '/foo'
assert ok?
@@ -34,10 +34,10 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "can modify instance variables available to routes" do
- mock_app {
+ mock_app do
before { @foo = 'bar' }
get('/foo') { @foo }
- }
+ end
get '/foo'
assert ok?
@@ -45,13 +45,13 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "allows redirects" do
- mock_app {
+ mock_app do
before { redirect '/bar' }
get('/foo') do
fail 'before block should have halted processing'
'ORLY?!'
end
- }
+ end
get '/foo'
assert redirect?
@@ -60,13 +60,13 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "does not modify the response with its return value" do
- mock_app {
+ mock_app do
before { 'Hello World!' }
- get '/foo' do
+ get('/foo') do
assert_equal [], response.body
'cool'
end
- }
+ end
get '/foo'
assert ok?
@@ -74,12 +74,12 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "does modify the response with halt" do
- mock_app {
+ mock_app do
before { halt 302, 'Hi' }
get '/foo' do
"should not happen"
end
- }
+ end
get '/foo'
assert_equal 302, response.status
@@ -87,10 +87,10 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "gives you access to params" do
- mock_app {
+ mock_app do
before { @foo = params['foo'] }
get('/foo') { @foo }
- }
+ end
get '/foo?foo=cool'
assert ok?
@@ -98,10 +98,10 @@ class BeforeFilterTest < Test::Unit::TestCase
end
it "properly unescapes parameters" do
- mock_app {
+ mock_app do
before { @foo = params['foo'] }
get('/foo') { @foo }
- }
+ end
get '/foo?foo=bar%3Abaz%2Fbend'
assert ok?
@@ -112,9 +112,7 @@ class BeforeFilterTest < Test::Unit::TestCase
base = Class.new(Sinatra::Base)
base.before { @foo = 'hello from superclass' }
- mock_app(base) {
- get('/foo') { @foo }
- }
+ mock_app(base) { get('/foo') { @foo } }
get '/foo'
assert_equal 'hello from superclass', body
@@ -122,11 +120,11 @@ class BeforeFilterTest < Test::Unit::TestCase
it 'does not run before filter when serving static files' do
ran_filter = false
- mock_app {
+ mock_app do
before { ran_filter = true }
set :static, true
set :public_folder, File.dirname(__FILE__)
- }
+ end
get "/#{File.basename(__FILE__)}"
assert ok?
assert_equal File.read(__FILE__), body
@@ -176,14 +174,14 @@ class AfterFilterTest < Test::Unit::TestCase
count = 0
mock_app do
get('/') { 'Hello World' }
- after {
+ after do
assert_equal 0, count
count = 1
- }
- after {
+ end
+ after do
assert_equal 1, count
count = 2
- }
+ end
end
get '/'
@@ -193,10 +191,10 @@ class AfterFilterTest < Test::Unit::TestCase
end
it "allows redirects" do
- mock_app {
+ mock_app do
get('/foo') { 'ORLY' }
after { redirect '/bar' }
- }
+ end
get '/foo'
assert redirect?
@@ -205,10 +203,10 @@ class AfterFilterTest < Test::Unit::TestCase
end
it "does not modify the response with its return value" do
- mock_app {
+ mock_app do
get('/foo') { 'cool' }
after { 'Hello World!' }
- }
+ end
get '/foo'
assert ok?
@@ -216,12 +214,12 @@ class AfterFilterTest < Test::Unit::TestCase
end
it "does modify the response with halt" do
- mock_app {
+ mock_app do
get '/foo' do
"should not be returned"
end
after { halt 302, 'Hi' }
- }
+ end
get '/foo'
assert_equal 302, response.status
@@ -245,11 +243,11 @@ class AfterFilterTest < Test::Unit::TestCase
it 'does not run after filter when serving static files' do
ran_filter = false
- mock_app {
+ mock_app do
after { ran_filter = true }
set :static, true
set :public_folder, File.dirname(__FILE__)
- }
+ end
get "/#{File.basename(__FILE__)}"
assert ok?
assert_equal File.read(__FILE__), body
@@ -308,9 +306,9 @@ class AfterFilterTest < Test::Unit::TestCase
before(:host_name => 'example.com') { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_HOST' => 'example.org' }
+ get('/', {}, { 'HTTP_HOST' => 'example.org' })
assert !ran
- get '/', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/', {}, { 'HTTP_HOST' => 'example.com' })
assert ran
end
@@ -320,11 +318,11 @@ class AfterFilterTest < Test::Unit::TestCase
before('/foo', :host_name => 'example.com') { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/', {}, { 'HTTP_HOST' => 'example.com' })
assert !ran
- get '/foo', {}, { 'HTTP_HOST' => 'example.org' }
+ get('/foo', {}, { 'HTTP_HOST' => 'example.org' })
assert !ran
- get '/foo', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/foo', {}, { 'HTTP_HOST' => 'example.com' })
assert ran
end
@@ -334,9 +332,9 @@ class AfterFilterTest < Test::Unit::TestCase
after(:host_name => 'example.com') { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_HOST' => 'example.org' }
+ get('/', {}, { 'HTTP_HOST' => 'example.org' })
assert !ran
- get '/', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/', {}, { 'HTTP_HOST' => 'example.com' })
assert ran
end
@@ -346,11 +344,11 @@ class AfterFilterTest < Test::Unit::TestCase
after('/foo', :host_name => 'example.com') { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/', {}, { 'HTTP_HOST' => 'example.com' })
assert !ran
- get '/foo', {}, { 'HTTP_HOST' => 'example.org' }
+ get('/foo', {}, { 'HTTP_HOST' => 'example.org' })
assert !ran
- get '/foo', {}, { 'HTTP_HOST' => 'example.com' }
+ get('/foo', {}, { 'HTTP_HOST' => 'example.com' })
assert ran
end
@@ -360,9 +358,9 @@ class AfterFilterTest < Test::Unit::TestCase
before(:user_agent => /foo/) { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_USER_AGENT' => 'bar' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'bar' })
assert !ran
- get '/', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert ran
end
@@ -372,11 +370,11 @@ class AfterFilterTest < Test::Unit::TestCase
before('/foo', :user_agent => /foo/) { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert !ran
- get '/foo', {}, { 'HTTP_USER_AGENT' => 'bar' }
+ get('/foo', {}, { 'HTTP_USER_AGENT' => 'bar' })
assert !ran
- get '/foo', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/foo', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert ran
end
@@ -406,9 +404,9 @@ class AfterFilterTest < Test::Unit::TestCase
after(:user_agent => /foo/) { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_USER_AGENT' => 'bar' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'bar' })
assert !ran
- get '/', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert ran
end
@@ -418,11 +416,11 @@ class AfterFilterTest < Test::Unit::TestCase
after('/foo', :user_agent => /foo/) { ran = true }
get('/') { 'welcome' }
end
- get '/', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert !ran
- get '/foo', {}, { 'HTTP_USER_AGENT' => 'bar' }
+ get('/foo', {}, { 'HTTP_USER_AGENT' => 'bar' })
assert !ran
- get '/foo', {}, { 'HTTP_USER_AGENT' => 'foo' }
+ get('/foo', {}, { 'HTTP_USER_AGENT' => 'foo' })
assert ran
end
@@ -433,7 +431,7 @@ class AfterFilterTest < Test::Unit::TestCase
get('/') { @type }
end
- get '/', {}, { 'HTTP_ACCEPT' => '*' }
+ get('/', {}, { 'HTTP_ACCEPT' => '*' })
assert_body 'txt'
end
end
View
42 test/haml_test.rb
@@ -5,10 +5,10 @@
class HAMLTest < Test::Unit::TestCase
def haml_app(&block)
- mock_app {
+ mock_app do
set :views, File.dirname(__FILE__) + '/views'
- get '/', &block
- }
+ get('/', &block)
+ end
get '/'
end
@@ -25,35 +25,29 @@ def haml_app(&block)
end
it "renders with inline layouts" do
- mock_app {
+ mock_app do
layout { %q(%h1= 'THIS. IS. ' + yield.upcase) }
get('/') { haml '%em Sparta' }
- }
+ end
get '/'
assert ok?
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
end
it "renders with file layouts" do
- haml_app {
- haml 'Hello World', :layout => :layout2
- }
+ haml_app { haml 'Hello World', :layout => :layout2 }
assert ok?
assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
end
it "raises error if template not found" do
- mock_app {
- get('/') { haml :no_such_template }
- }
+ mock_app { get('/') { haml :no_such_template } }
assert_raise(Errno::ENOENT) { get('/') }
end
it "passes HAML options to the Haml engine" do
mock_app {
- get '/' do
- haml "!!!\n%h1 Hello World", :format => :html5
- end
+ get('/') { haml "!!!\n%h1 Hello World", :format => :html5 }
}
get '/'
assert ok?
@@ -61,27 +55,23 @@ def haml_app(&block)
end
it "passes default HAML options to the Haml engine" do
- mock_app {
+ mock_app do
set :haml, {:format => :html5}
- get '/' do
- haml "!!!\n%h1 Hello World"
- end
- }
+ get('/') { haml "!!!\n%h1 Hello World" }
+ end
get '/'
assert ok?
assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
end
it "merges the default HAML options with the overrides and passes them to the Haml engine" do
- mock_app {
+ mock_app do
set :haml, {:format => :html5, :attr_wrapper => '"'} # default HAML attr are <tag attr='single-quoted'>
- get '/' do
- haml "!!!\n%h1{:class => :header} Hello World"
- end
- get '/html4' do
+ get('/') { haml "!!!\n%h1{:class => :header} Hello World" }
+ get('/html4') {
haml "!!!\n%h1{:class => 'header'} Hello World", :format => :html4
- end
- }
+ }
+ end
get '/'
assert ok?
assert_equal "<!DOCTYPE html>\n<h1 class=\"header\">Hello World</h1>\n", body
View
382 test/helpers_test.rb
@@ -10,7 +10,7 @@ def status_app(code, &block)
code += 2 if [204, 205, 304].include? code
block ||= proc { }
mock_app do
- get '/' do
+ get('/') do
status code
instance_eval(&block).inspect
end
@@ -119,22 +119,16 @@ def status_app(code, &block)
describe 'body' do
it 'takes a block for defered body generation' do
- mock_app {
- get '/' do
- body { 'Hello World' }
- end
- }
+ mock_app do
+ get('/') { body { 'Hello World' } }
+ end
get '/'
assert_equal 'Hello World', body
end
it 'takes a String, Array, or other object responding to #each' do
- mock_app {
- get '/' do
- body 'Hello World'
- end
- }
+ mock_app { get('/') { body 'Hello World' } }
get '/'
assert_equal 'Hello World', body
@@ -143,12 +137,12 @@ def status_app(code, &block)
describe 'redirect' do
it 'uses a 302 when only a path is given' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
redirect '/foo'
fail 'redirect should halt'
end
- }
+ end
get '/'
assert_equal 302, status
@@ -157,12 +151,12 @@ def status_app(code, &block)
end
it 'uses the code given when specified' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
redirect '/foo', 301
fail 'redirect should halt'
end
- }
+ end
get '/'
assert_equal 301, status
@@ -171,11 +165,7 @@ def status_app(code, &block)
end
it 'redirects back to request.referer when passed back' do
- mock_app {
- get '/try_redirect' do
- redirect back
- end
- }
+ mock_app { get('/try_redirect') { redirect back } }
request = Rack::MockRequest.new(@app)
response = request.get('/try_redirect', 'HTTP_REFERER' => '/foo')
@@ -184,11 +174,7 @@ def status_app(code, &block)
end
it 'redirects using a non-standard HTTP port' do
- mock_app {
- get '/' do
- redirect '/foo'
- end
- }
+ mock_app { get('/') { redirect '/foo' } }
request = Rack::MockRequest.new(@app)
response = request.get('/', 'SERVER_PORT' => '81')
@@ -196,11 +182,7 @@ def status_app(code, &block)
end
it 'redirects using a non-standard HTTPS port' do
- mock_app {
- get '/' do
- redirect '/foo'
- end
- }
+ mock_app { get('/') { redirect '/foo' } }
request = Rack::MockRequest.new(@app)
response = request.get('/', 'SERVER_PORT' => '444')
@@ -209,7 +191,7 @@ def status_app(code, &block)
it 'uses 303 for post requests if request is HTTP 1.1' do
mock_app { post('/') { redirect '/'} }
- post '/', {}, 'HTTP_VERSION' => 'HTTP/1.1'
+ post('/', {}, 'HTTP_VERSION' => 'HTTP/1.1')
assert_equal 303, status
assert_equal '', body
assert_equal 'http://example.org/', response['Location']
@@ -217,18 +199,14 @@ def status_app(code, &block)
it 'uses 302 for post requests if request is HTTP 1.0' do
mock_app { post('/') { redirect '/'} }
- post '/', {}, 'HTTP_VERSION' => 'HTTP/1.0'
+ post('/', {}, 'HTTP_VERSION' => 'HTTP/1.0')
assert_equal 302, status
assert_equal '', body
assert_equal 'http://example.org/', response['Location']
end
it 'works behind a reverse proxy' do
- mock_app do
- get '/' do
- redirect '/foo'
- end
- end
+ mock_app { get('/') { redirect '/foo' } }
request = Rack::MockRequest.new(@app)
response = request.get('/', 'HTTP_X_FORWARDED_HOST' => 'example.com', 'SERVER_PORT' => '8080')
@@ -237,7 +215,7 @@ def status_app(code, &block)
it 'accepts absolute URIs' do
mock_app do
- get '/' do
+ get('/') do
redirect 'http://google.com'
fail 'redirect should halt'
end
@@ -251,7 +229,7 @@ def status_app(code, &block)
it 'accepts absolute URIs with a different schema' do
mock_app do
- get '/' do
+ get('/') do
redirect 'mailto:jsmith@example.com'
fail 'redirect should halt'
end
@@ -266,12 +244,12 @@ def status_app(code, &block)
describe 'error' do
it 'sets a status code and halts' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
error 501
fail 'error should halt'
end
- }
+ end
get '/'
assert_equal 501, status
@@ -279,12 +257,12 @@ def status_app(code, &block)
end
it 'takes an optional body' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
error 501, 'FAIL'
fail 'error should halt'
end
- }
+ end
get '/'
assert_equal 501, status
@@ -292,12 +270,12 @@ def status_app(code, &block)
end
it 'uses a 500 status code when first argument is a body' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
error 'FAIL'
fail 'error should halt'
end
- }
+ end
get '/'
assert_equal 500, status
@@ -307,12 +285,12 @@ def status_app(code, &block)
describe 'not_found' do
it 'halts with a 404 status' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
not_found
fail 'not_found should halt'
end
- }
+ end
get '/'
assert_equal 404, status
@@ -320,12 +298,12 @@ def status_app(code, &block)
end
it 'does not set a X-Cascade header' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
not_found
fail 'not_found should halt'
end
- }
+ end
get '/'
assert_equal 404, status
@@ -335,12 +313,12 @@ def status_app(code, &block)
describe 'headers' do
it 'sets headers on the response object when given a Hash' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
headers 'X-Foo' => 'bar', 'X-Baz' => 'bling'
'kthx'
end
- }
+ end
get '/'
assert ok?
@@ -350,12 +328,12 @@ def status_app(code, &block)
end
it 'returns the response headers hash when no hash provided' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
headers['X-Foo'] = 'bar'
'kthx'
end
- }
+ end
get '/'
assert ok?
@@ -365,30 +343,30 @@ def status_app(code, &block)
describe 'session' do
it 'uses the existing rack.session' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
session[:foo]
end
- }
+ end
- get '/', {}, { 'rack.session' => { :foo => 'bar' } }
+ get('/', {}, { 'rack.session' => { :foo => 'bar' } })
assert_equal 'bar', body
end
it 'creates a new session when none provided' do
- mock_app {
+ mock_app do
enable :sessions
- get '/' do
+ get('/') do
assert session[:foo].nil?
session[:foo] = 'bar'
redirect '/hi'
end
- get '/hi' do
+ get('/hi') do
"hi #{session[:foo]}"
end
- }
+ end
get '/'
follow_redirect!
@@ -398,7 +376,8 @@ def status_app(code, &block)
it 'inserts session middleware' do
mock_app do
enable :sessions
- get '/' do
+
+ get('/') do
assert env['rack.session']
assert env['rack.session.options']
'ok'
@@ -412,7 +391,8 @@ def status_app(code, &block)
it 'sets a default session secret' do
mock_app do
enable :sessions
- get '/' do
+
+ get('/') do
secret = env['rack.session.options'][:secret]
assert secret
assert_equal secret, settings.session_secret
@@ -428,7 +408,8 @@ def status_app(code, &block)
mock_app do
enable :sessions
disable :session_secret
- get '/' do
+
+ get('/') do
assert !env['rack.session.options'].include?(:session_secret)
'ok'
end
@@ -441,7 +422,8 @@ def status_app(code, &block)
it 'accepts an options hash' do
mock_app do
set :sessions, :foo => :bar
- get '/' do
+
+ get('/') do
assert_equal env['rack.session.options'][:foo], :bar
'ok'
end
@@ -476,13 +458,13 @@ def status_app(code, &block)
end
test 'Base.mime_type registers mime type' do
- mock_app {
+ mock_app do
mime_type :foo, 'application/foo'
- get '/' do
+ get('/') do
"foo is #{mime_type(:foo)}"
end
- }
+ end
get '/'
assert_equal 'foo is application/foo', body
@@ -490,12 +472,12 @@ def status_app(code, &block)
describe 'content_type' do
it 'sets the Content-Type header' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
content_type 'text/plain'
'Hello World'
end
- }
+ end
get '/'
assert_equal 'text/plain;charset=utf-8', response['Content-Type']
@@ -503,12 +485,12 @@ def status_app(code, &block)
end
it 'takes media type parameters (like charset=)' do
- mock_app {
- get '/' do
+ mock_app do
+ get('/') do
content_type 'text/html', :charset => 'latin1'
"<h1>Hello, World</h1>"
end
- }
+ end
get '/'
assert ok?
@@ -518,12 +500,12 @@ def status_app(code, &block)
it "looks up symbols in Rack's mime types dictionary" do
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
- mock_app {
- get '/foo.xml' do
+ mock_app do
+ get('/foo.xml') do
content_type :foo
"I AM FOO"
end
- }
+ end
get '/foo.xml'
assert ok?
@@ -532,12 +514,12 @@ def status_app(code, &block)
end
it 'fails when no mime type is registered for the argument provided' do
- mock_app {
- get '/foo.xml' do
+ mock_app do
+ get('/foo.xml') do
content_type :bizzle
"I AM FOO"
end
- }
+ end
assert_raise(RuntimeError) { get '/foo.xml' }
end
@@ -549,7 +531,7 @@ def status_app(code, &block)
mime_type :bar, 'application/bar'
mime_type :baz, 'application/baz'
add_charset << mime_type(:baz)
- get '/' do
+ get('/') do
assert_equal content_type(:txt), 'text/plain;charset=utf-8'
assert_equal content_type(:css), 'text/css;charset=utf-8'
assert_equal content_type(:html), 'text/html;charset=utf-8'
@@ -565,28 +547,31 @@ def status_app(code, &block)
"done"
end
end
+
get '/'
assert tests_ran
end
it 'handles already present params' do
mock_app do
- get '/' do
+ get('/') do
content_type 'foo/bar;level=1', :charset => 'utf-8'
'ok'
end
end
+
get '/'
assert_equal 'foo/bar;level=1, charset=utf-8', response['Content-Type']
end
it 'does not add charset if present' do
mock_app do
- get '/' do
+ get('/') do
content_type 'text/plain;charset=utf-16'
'ok'
end
end
+
get '/'
assert_equal 'text/plain;charset=utf-16', response['Content-Type']
end
@@ -594,12 +579,12 @@ def status_app(code, &block)
describe 'attachment' do
def attachment_app(filename=nil)
- mock_app {
- get '/attachment' do
+ mock_app do
+ get('/attachment') do
attachment filename
response.write("<sinatra></sinatra>")
end
- }
+ end
end
it 'sets the Content-Type response header' do
@@ -618,12 +603,13 @@ def attachment_app(filename=nil)
it 'sets the Content-Type response header without extname' do
mock_app do
- get '/attachment' do
+ get('/attachment') do
content_type :atom
attachment 'test.xml'
response.write("<sinatra></sinatra>")
end
end
+
get '/attachment'
assert_equal 'application/atom+xml', response['Content-Type']
assert_equal '<sinatra></sinatra>', body
@@ -697,9 +683,7 @@ def send_file_app(opts={})
it "returns a 404 when not found" do
mock_app {
- get '/' do
- send_file 'this-file-does-not-exist.txt'
- end
+ get('/') { send_file 'this-file-does-not-exist.txt' }
}
get '/'
assert not_found?
@@ -746,7 +730,7 @@ def send_file_app(opts={})
it "does not override Content-Type if already set and no explicit type is given" do
path = @file
mock_app do
- get '/' do
+ get('/') do
content_type :png
send_file path
end
@@ -758,7 +742,7 @@ def send_file_app(opts={})
it "does override Content-Type even if already set, if explicit type is given" do
path = @file
mock_app do
- get '/' do
+ get('/') do
content_type :png
send_file path, :type => :gif
end
@@ -771,12 +755,12 @@ def send_file_app(opts={})
describe 'cache_control' do
setup do
mock_app do
- get '/foo' do
+ get('/foo') do
cache_control :public, :no_cache, :max_age => 60.0
'Hello World'
end
- get '/bar' do
+ get('/bar') do
cache_control :public, :no_cache
'Hello World'
end
@@ -797,20 +781,16 @@ def send_file_app(opts={})
describe 'expires' do
setup do
mock_app do
- get '/foo' do
+ get('/foo') do
expires 60, :public, :no_cache
'Hello World'
end
- get '/bar' do
- expires Time.now
- end
+ get('/bar') { expires Time.now }
- get '/baz' do
- expires Time.at(0)
- end
+ get('/baz') { expires Time.at(0) }
- get '/blah' do
+ get('/blah') do
obj = Object.new
def obj.method_missing(*a, &b) 60.send(*a, &b) end
def obj.is_a?(thing) 60.is_a?(thing) end
@@ -818,9 +798,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
'Hello World'
end
- get '/boom' do
- expires '9999'
- end
+ get('/boom') { expires '9999' }
end
end
@@ -856,9 +834,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
describe 'last_modified' do
it 'ignores nil' do
- mock_app do
- get '/' do last_modified nil; 200; end
- end
+ mock_app { get('/') { last_modified nil; 200; } }
get '/'
assert ! response['Last-Modified']
@@ -866,7 +842,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'does not change a status other than 200' do
mock_app do
- get '/' do
+ get('/') do
status 299
last_modified Time.at(0)
'ok'
@@ -883,7 +859,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
describe "with #{last_modified_time.class.name}" do
setup do
mock_app do
- get '/' do
+ get('/') do
last_modified last_modified_time
'Boo!'
end
@@ -910,12 +886,12 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "when there's an invalid If-Modified-Since header" do
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' })
assert_equal @last_modified_time.httpdate, response['Last-Modified']
end
it 'conditional GET misses and returns a body' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' })
assert_equal 200, status
assert_equal 'Boo!', body
end
@@ -923,28 +899,28 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "when the resource has been modified since the If-Modified-Since header date" do
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate })
assert_equal @last_modified_time.httpdate, response['Last-Modified']
end
it 'conditional GET misses and returns a body' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate })
assert_equal 200, status
assert_equal 'Boo!', body
end
it 'does not rely on string comparison' do
mock_app do
- get '/compare' do
+ get('/compare') do
last_modified "Mon, 18 Oct 2010 20:57:11 GMT"
"foo"
end
end
- get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2010 23:43:52 GMT' }
+ get('/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2010 23:43:52 GMT' })
assert_equal 200, status
assert_equal 'foo', body
- get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' }
+ get('/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' })
assert_equal 304, status
assert_equal '', body
end
@@ -952,12 +928,12 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "when the resource has been modified on the exact If-Modified-Since header date" do
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate })
assert_equal @last_modified_time.httpdate, response['Last-Modified']
end
it 'conditional GET matches and halts' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate }
+ get( '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate })
assert_equal 304, status
assert_equal '', body
end
@@ -965,12 +941,12 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "when the resource hasn't been modified since the If-Modified-Since header date" do
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate })
assert_equal @last_modified_time.httpdate, response['Last-Modified']
end
it 'conditional GET matches and halts' do
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate }
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate })
assert_equal 304, status
assert_equal '', body
end
@@ -978,13 +954,13 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-Unmodified-Since" do
it 'results in 200 if resource has not been modified' do
- get '/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' }
+ get('/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' })
assert_equal 200, status
assert_equal 'Boo!', body
end
it 'results in 412 if resource has been modified' do
- get '/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => Time.at(0).httpdate }
+ get('/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => Time.at(0).httpdate })
assert_equal 412, status
assert_equal '', body
end
@@ -997,13 +973,13 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "safe requests" do
it 'returns 200 for normal requests' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
end
- get('/')
+ get '/'
assert_status 200
assert_body 'ok'
end
@@ -1011,7 +987,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-None-Match" do
it 'returns 304 when If-None-Match is *' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1024,7 +1000,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match is * for new resources' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1037,7 +1013,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 304 when If-None-Match is * for existing resources' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1050,7 +1026,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 304 when If-None-Match is the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1063,7 +1039,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 304 when If-None-Match includes the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1076,7 +1052,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match does not include the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1089,7 +1065,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'ignores If-Modified-Since if If-None-Match does not match' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
last_modified Time.at(0)
'ok'
@@ -1103,7 +1079,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'does not change a status code other than 2xx or 304' do
mock_app do
- get '/' do
+ get('/') do
status 499
etag 'foo'
'ok'
@@ -1117,7 +1093,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'does change 2xx status codes' do
mock_app do
- get '/' do
+ get('/') do
status 299
etag 'foo'
'ok'
@@ -1131,7 +1107,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'does not send a body on 304 status codes' do
mock_app do
- get '/' do
+ get('/') do
status 304
etag 'foo'
'ok'
@@ -1147,7 +1123,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-Match" do
it 'returns 200 when If-Match is the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1160,7 +1136,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match includes the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1173,7 +1149,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match is *' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1186,7 +1162,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match is * for new resources' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1199,7 +1175,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match is * for existing resources' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1212,7 +1188,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match does not include the etag' do
mock_app do
- get '/' do
+ get('/') do
etag 'foo'
'ok'
end
@@ -1228,13 +1204,13 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "idempotent requests" do
it 'returns 200 for normal requests' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
end
- put('/')
+ put '/'
assert_status 200
assert_body 'ok'
end
@@ -1242,7 +1218,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-None-Match" do
it 'returns 412 when If-None-Match is *' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1255,7 +1231,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match is * for new resources' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1268,7 +1244,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-None-Match is * for existing resources' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1294,7 +1270,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-None-Match includes the etag' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1307,7 +1283,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match does not include the etag' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1320,7 +1296,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'ignores If-Modified-Since if If-None-Match does not match' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
last_modified Time.at(0)
'ok'
@@ -1336,7 +1312,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-Match" do
it 'returns 200 when If-Match is the etag' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1349,7 +1325,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match includes the etag' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1362,7 +1338,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match is *' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1375,7 +1351,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match is * for new resources' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1388,7 +1364,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match is * for existing resources' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1401,7 +1377,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match does not include the etag' do
mock_app do
- put '/' do
+ put('/') do
etag 'foo'
'ok'
end
@@ -1417,7 +1393,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "post requests" do
it 'returns 200 for normal requests' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1431,7 +1407,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-None-Match" do
it 'returns 200 when If-None-Match is *' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1444,7 +1420,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match is * for new resources' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1457,7 +1433,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-None-Match is * for existing resources' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1470,7 +1446,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-None-Match is the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1483,7 +1459,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-None-Match includes the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1496,7 +1472,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-None-Match does not include the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1509,7 +1485,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'ignores If-Modified-Since if If-None-Match does not match' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
last_modified Time.at(0)
'ok'
@@ -1525,7 +1501,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
context "If-Match" do
it 'returns 200 when If-Match is the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1538,7 +1514,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match includes the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1551,7 +1527,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match is *' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1564,7 +1540,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match is * for new resources' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo', :new_resource => true
'ok'
end
@@ -1577,7 +1553,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 200 when If-Match is * for existing resources' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo', :new_resource => false
'ok'
end
@@ -1590,7 +1566,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'returns 412 when If-Match does not include the etag' do
mock_app do
- post '/' do
+ post('/') do
etag 'foo'
'ok'
end
@@ -1605,7 +1581,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'uses a weak etag with the :weak option' do
mock_app do
- get '/' do
+ get('/') do
etag 'FOO', :weak
"that's weak, dude."
end
@@ -1616,24 +1592,20 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'raises an ArgumentError for an invalid strength' do
mock_app do
- get '/' do
+ get('/') do
etag 'FOO', :w00t
"that's weak, dude."
end
end
- assert_raise(ArgumentError) { get '/' }
+ assert_raise(ArgumentError) { get('/') }
end
end
describe 'back' do
it "makes redirecting back pretty" do
- mock_app {
- get '/foo' do
- redirect back
- end
- }
+ mock_app { get('/foo') { redirect back } }
- get '/foo', {}, 'HTTP_REFERER' => 'http://github.com'
+ get('/foo', {}, 'HTTP_REFERER' => 'http://github.com')
assert redirect?
assert_equal "http://github.com", response.location
end
@@ -1693,7 +1665,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'logging works when logging is enabled' do
mock_app do
enable :logging
- get '/' do
+ get('/') do
logger.info "Program started"
logger.warn "Nothing to do!"
end
@@ -1707,7 +1679,7 @@ def obj.is_a?(thing) 60.is_a?(thing) end
it 'logging works when logging is disable, but no output is produced' do
mock_app do
disable :logging
- get '/' do
+ get('/') do
logger.info "Program started"
logger.warn "Nothing to do!"
end
@@ -1734,17 +1706,13 @@ module ::HelperTwo; def two; '2'; end; end
describe 'Adding new helpers' do
it 'takes a list of modules to mix into the app' do
- mock_app {
+ mock_app do
helpers ::HelperOne, ::HelperTwo
- get '/one' do
- one
- end
+ get('/one') { one }
- get '/two' do
- two
- end
- }
+ get('/two') { two }
+ end
get '/one'
assert_equal '1', body
@@ -1754,32 +1722,26 @@ module ::HelperTwo; def two; '2'; end; end
end
it 'takes a block to mix into the app' do
- mock_app {
+ mock_app do
helpers do
def foo
'foo'
end
end
- get '/' do
- foo
- end
- }
+ get('/') { foo }
+ end