Permalink
Browse files

Allow assertions in mock_app request context

I changed the ".should." style to use "fail" when we
converted to test/unit style but I'd rather use asserts
here.
  • Loading branch information...
1 parent c2849ff commit 661090eb53ca856f690bcbef1e640b13511bf24e @rtomayko rtomayko committed Jan 15, 2009
Showing with 22 additions and 17 deletions.
  1. +2 −2 test/filter_test.rb
  2. +5 −0 test/helper.rb
  3. +1 −1 test/helpers_test.rb
  4. +2 −2 test/mapped_error_test.rb
  5. +12 −12 test/routing_test.rb
View
@@ -6,11 +6,11 @@
mock_app do
get('/') { 'Hello World' }
before {
- fail 'count != 0' if count != 0
+ assert_equal 0, count
count = 1
}
before {
- fail 'count != 1' if count != 1
+ assert_equal 1, count
count = 2
}
end
View
@@ -18,3 +18,8 @@ def mock_app(base=Sinatra::Base, &block)
@app = Sinatra.new(base, &block)
end
end
+
+class Sinatra::Base
+ # Allow assertions in request context
+ include Test::Unit::Assertions
+end
View
@@ -142,7 +142,7 @@
it 'creates a new session when none provided' do
mock_app {
get '/' do
- fail "session != {}" unless session.empty?
+ assert session.empty?
session[:foo] = 'bar'
'Hi'
end
@@ -34,8 +34,8 @@ class FooError < RuntimeError
mock_app {
set :raise_errors, false
error(FooError) {
- fail "!env.include?('sinatra.error')" if !env.include?('sinatra.error')
- fail unless env['sinatra.error'].kind_of?(FooError)
+ assert env.include?('sinatra.error')
+ assert env['sinatra.error'].kind_of?(FooError)
'looks good'
}
get '/' do
View
@@ -27,8 +27,8 @@
it "exposes params with indifferent hash" do
mock_app {
get '/:foo' do
- fail unless params['foo'] == 'bar'
- fail unless params[:foo] == 'bar'
+ assert_equal 'bar', params['foo']
+ assert_equal 'bar', params[:foo]
'well, alright'
end
}
@@ -39,8 +39,8 @@
it "merges named params and query string params in params" do
mock_app {
get '/:foo' do
- fail unless params['foo'] == 'bar'
- fail unless params['baz'] == 'biz'
+ assert_equal 'bar', params['foo']
+ assert_equal 'biz', params['baz']
end
}
get '/bar?baz=biz'
@@ -80,7 +80,7 @@
it "supports single splat params like /*" do
mock_app {
get '/*' do
- fail unless params['splat'].kind_of?(Array)
+ assert params['splat'].kind_of?(Array)
params['splat'].join "\n"
end
}
@@ -95,7 +95,7 @@
it "supports mixing multiple splat params like /*/foo/*/*" do
mock_app {
get '/*/foo/*/*' do
- fail unless params['splat'].kind_of?(Array)
+ assert params['splat'].kind_of?(Array)
params['splat'].join "\n"
end
}
@@ -110,8 +110,8 @@
it "supports mixing named and splat params like /:foo/*" do
mock_app {
get '/:foo/*' do
- fail unless params['foo'] == 'foo'
- fail unless params['splat'] == ['bar/baz']
+ assert_equal 'foo', params['foo']
+ assert_equal ['bar/baz'], params['splat']
end
}
@@ -134,8 +134,8 @@
it "URL decodes named parameters and splats" do
mock_app {
get '/:foo/*' do
- fail unless params['foo'] == 'hello world'
- fail unless params['splat'] == ['how are you']
+ assert_equal 'hello world', params['foo']
+ assert_equal ['how are you'], params['splat']
nil
end
}
@@ -159,7 +159,7 @@
it 'makes regular expression captures available in params[:captures]' do
mock_app {
get(/^\/fo(.*)\/ba(.*)/) do
- fail unless params[:captures] == ['orooomma', 'f']
+ assert_equal ['orooomma', 'f'], params[:captures]
'right on'
end
}
@@ -190,7 +190,7 @@
end
get '/*' do
- fail if params.include?('foo')
+ assert !params.include?('foo')
'Hello World'
end
}

0 comments on commit 661090e

Please sign in to comment.