Skip to content
This repository
Newer
Older
100644 58 lines (45 sloc) 1.496 kb
0400c671 » grosser
2012-07-18 make all tests runnable via ruby test_file.rb by loading the helper a…
1 require File.expand_path '../helper', __FILE__
81437f0b » jferris
2010-01-20 Initial Rack middleware
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] }
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
8 stack = Airbrake::Rack.new(app)
81437f0b » jferris
2010-01-20 Initial Rack middleware
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
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
16 Airbrake.stubs(:notify_or_ignore)
81437f0b » jferris
2010-01-20 Initial Rack middleware
17
18 exception = build_exception
47908c93 » jferris
2010-01-20 Extract request info from rack env
19 environment = { 'key' => 'value' }
81437f0b » jferris
2010-01-20 Initial Rack middleware
20 app = lambda do |env|
21 raise exception
22 end
23
24 begin
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
25 stack = Airbrake::Rack.new(app)
47908c93 » jferris
2010-01-20 Extract request info from rack env
26 stack.call(environment)
81437f0b » jferris
2010-01-20 Initial Rack middleware
27 rescue Exception => raised
28 assert_equal exception, raised
29 else
30 flunk "Didn't raise an exception"
31 end
32
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
33 assert_received(Airbrake, :notify_or_ignore) do |expect|
47908c93 » jferris
2010-01-20 Extract request info from rack env
34 expect.with(exception, :rack_env => environment)
35 end
81437f0b » jferris
2010-01-20 Initial Rack middleware
36 end
37
38 should "deliver an exception in rack.exception" do
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
39 Airbrake.stubs(:notify_or_ignore)
81437f0b » jferris
2010-01-20 Initial Rack middleware
40 exception = build_exception
47908c93 » jferris
2010-01-20 Extract request info from rack env
41 environment = { 'key' => 'value' }
81437f0b » jferris
2010-01-20 Initial Rack middleware
42
43 response = [200, {}, ['okay']]
44 app = lambda do |env|
45 env['rack.exception'] = exception
46 response
47 end
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
48 stack = Airbrake::Rack.new(app)
81437f0b » jferris
2010-01-20 Initial Rack middleware
49
47908c93 » jferris
2010-01-20 Extract request info from rack env
50 actual_response = stack.call(environment)
81437f0b » jferris
2010-01-20 Initial Rack middleware
51
52 assert_equal response, actual_response
ceb0feb7 » jyurek
2011-08-11 WIP: Hoptoad -> Airbrake
53 assert_received(Airbrake, :notify_or_ignore) do |expect|
47908c93 » jferris
2010-01-20 Extract request info from rack env
54 expect.with(exception, :rack_env => environment)
55 end
81437f0b » jferris
2010-01-20 Initial Rack middleware
56 end
57
58 end
Something went wrong with that request. Please try again.