Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 58 lines (45 sloc) 1.496 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
require File.expand_path '../helper', __FILE__

class RackTest < Test::Unit::TestCase

  should "call the upstream app with the environment" do
    environment = { 'key' => 'value' }
    app = lambda { |env| ['response', {}, env] }
    stack = Airbrake::Rack.new(app)

    response = stack.call(environment)

    assert_equal ['response', {}, environment], response
  end

  should "deliver an exception raised while calling an upstream app" do
    Airbrake.stubs(:notify_or_ignore)

    exception = build_exception
    environment = { 'key' => 'value' }
    app = lambda do |env|
      raise exception
    end

    begin
      stack = Airbrake::Rack.new(app)
      stack.call(environment)
    rescue Exception => raised
      assert_equal exception, raised
    else
      flunk "Didn't raise an exception"
    end

    assert_received(Airbrake, :notify_or_ignore) do |expect|
      expect.with(exception, :rack_env => environment)
    end
  end

  should "deliver an exception in rack.exception" do
    Airbrake.stubs(:notify_or_ignore)
    exception = build_exception
    environment = { 'key' => 'value' }

    response = [200, {}, ['okay']]
    app = lambda do |env|
      env['rack.exception'] = exception
      response
    end
    stack = Airbrake::Rack.new(app)

    actual_response = stack.call(environment)

    assert_equal response, actual_response
    assert_received(Airbrake, :notify_or_ignore) do |expect|
      expect.with(exception, :rack_env => environment)
    end
  end

end
Something went wrong with that request. Please try again.