Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (47 sloc) 1.561 kB
0400c67 @grosser make all tests runnable via ruby test_file.rb by loading the helper a…
grosser authored
1 require File.expand_path '../helper', __FILE__
81437f0 @jferris Initial Rack middleware
jferris authored
2
3 class RackTest < Test::Unit::TestCase
4
5 should "call the upstream app with the environment" do
6 environment = { 'key' => 'value' }
7 app = lambda { |env| ['response', {}, env] }
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
8 stack = Airbrake::Rack.new(app)
81437f0 @jferris Initial Rack middleware
jferris authored
9
10 response = stack.call(environment)
11
12 assert_equal ['response', {}, environment], response
13 end
14
15 should "deliver an exception raised while calling an upstream app" do
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
16 Airbrake.stubs(:notify_or_ignore)
81437f0 @jferris Initial Rack middleware
jferris authored
17
18 exception = build_exception
47908c9 @jferris Extract request info from rack env
jferris authored
19 environment = { 'key' => 'value' }
81437f0 @jferris Initial Rack middleware
jferris authored
20 app = lambda do |env|
21 raise exception
22 end
23
24 begin
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
25 stack = Airbrake::Rack.new(app)
47908c9 @jferris Extract request info from rack env
jferris authored
26 stack.call(environment)
81437f0 @jferris Initial Rack middleware
jferris authored
27 rescue Exception => raised
28 assert_equal exception, raised
29 else
30 flunk "Didn't raise an exception"
31 end
32
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
33 assert_received(Airbrake, :notify_or_ignore) do |expect|
47908c9 @jferris Extract request info from rack env
jferris authored
34 expect.with(exception, :rack_env => environment)
35 end
81437f0 @jferris Initial Rack middleware
jferris authored
36 end
37
b898c66 @rodrigosaito Handle error when variable sinatra.error is present
rodrigosaito authored
38 %w(rack.exception sinatra.error).each do |ex|
39
40 should "deliver an exception in #{ex}" do
41 Airbrake.stubs(:notify_or_ignore)
42 exception = build_exception
43 environment = { 'key' => 'value' }
44
45 response = [200, {}, ['okay']]
46 app = lambda do |env|
47 env[ex] = exception
48 response
49 end
50 stack = Airbrake::Rack.new(app)
81437f0 @jferris Initial Rack middleware
jferris authored
51
b898c66 @rodrigosaito Handle error when variable sinatra.error is present
rodrigosaito authored
52 actual_response = stack.call(environment)
81437f0 @jferris Initial Rack middleware
jferris authored
53
b898c66 @rodrigosaito Handle error when variable sinatra.error is present
rodrigosaito authored
54 assert_equal response, actual_response
55 assert_received(Airbrake, :notify_or_ignore) do |expect|
56 expect.with(exception, :rack_env => environment)
57 end
47908c9 @jferris Extract request info from rack env
jferris authored
58 end
b898c66 @rodrigosaito Handle error when variable sinatra.error is present
rodrigosaito authored
59
81437f0 @jferris Initial Rack middleware
jferris authored
60 end
61
62 end
Something went wrong with that request. Please try again.