Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 59 lines (45 sloc) 1.492 kB
81437f0 @jferris Initial Rack middleware
jferris authored
1 require File.dirname(__FILE__) + '/helper'
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
38 should "deliver an exception in rack.exception" do
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
39 Airbrake.stubs(:notify_or_ignore)
81437f0 @jferris Initial Rack middleware
jferris authored
40 exception = build_exception
47908c9 @jferris Extract request info from rack env
jferris authored
41 environment = { 'key' => 'value' }
81437f0 @jferris Initial Rack middleware
jferris authored
42
43 response = [200, {}, ['okay']]
44 app = lambda do |env|
45 env['rack.exception'] = exception
46 response
47 end
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
48 stack = Airbrake::Rack.new(app)
81437f0 @jferris Initial Rack middleware
jferris authored
49
47908c9 @jferris Extract request info from rack env
jferris authored
50 actual_response = stack.call(environment)
81437f0 @jferris Initial Rack middleware
jferris authored
51
52 assert_equal response, actual_response
ceb0feb @jyurek WIP: Hoptoad -> Airbrake
jyurek authored
53 assert_received(Airbrake, :notify_or_ignore) do |expect|
47908c9 @jferris Extract request info from rack env
jferris authored
54 expect.with(exception, :rack_env => environment)
55 end
81437f0 @jferris Initial Rack middleware
jferris authored
56 end
57
58 end
Something went wrong with that request. Please try again.