Sha256: dd8f58497e492206de47ad2e2d779b5b5d8f44f249515c5df9de409b5d4131b5

Contents?: true

Size: 1.52 KB

Versions: 19

Compression:

Stored size: 1.52 KB

Contents

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

  %w(rack.exception sinatra.error).each do |ex|

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

      response = [200, {}, ['okay']]
      app = lambda do |env|
        env[ex] = 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

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
airbrakeV4rails5-4.3.8 test/rack_test.rb
airbrake-4.3.8 test/rack_test.rb
airbrake-4.3.7 test/rack_test.rb
airbrake-4.3.6 test/rack_test.rb
airbrake-4.3.5 test/rack_test.rb
airbrake-4.3.4 test/rack_test.rb
airbrake-4.3.3 test/rack_test.rb
airbrake-4.3.2 test/rack_test.rb
airbrake-4.3.1 test/rack_test.rb
airbrake-4.3.0 test/rack_test.rb
airbrake-4.2.1 test/rack_test.rb
airbrake-4.2.0 test/rack_test.rb
airbrake-4.1.0 test/rack_test.rb
airbrake-4.0.0 test/rack_test.rb
airbrake-3.2.1 test/rack_test.rb
airbrake-3.2.0 test/rack_test.rb
airbrake-3.1.17 test/rack_test.rb
airbrake-3.1.16 test/rack_test.rb
airbrake-3.1.15 test/rack_test.rb