Sha256: e68a83849e487aa710f9b69a099c708f6af19a4316b05034f3a3214ae178eea4

Contents?: true

Size: 1.5 KB

Versions: 35

Compression:

Stored size: 1.5 KB

Contents

require File.dirname(__FILE__) + '/helper'

class RackTest < Test::Unit::TestCase

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

    response = stack.call(environment)

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

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

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

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

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

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

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

    actual_response = stack.call(environment)

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

end

Version data entries

35 entries across 35 versions & 6 rubygems

Version Path
square-hoptoad_notifier-2.4.9 test/rack_test.rb
hoptoad_notifier-2.4.11 test/rack_test.rb
hoptoad_notifier-2.4.10 test/rack_test.rb
hoptoad_notifier-2.4.9 test/rack_test.rb
square-hoptoad_notifier-2.4.8 test/rack_test.rb
hoptoad_notifier-2.4.8 test/rack_test.rb
hoptoad_notifier-2.4.7 test/rack_test.rb
hoptoad_notifier-2.4.6 test/rack_test.rb
hoptoad_notifier-2.4.5 test/rack_test.rb
hoptoad_notifier-2.4.4 test/rack_test.rb
hoptoad_notifier-2.4.2 test/rack_test.rb
hoptoad_notifier-2.4.1 test/rack_test.rb
hoptoad_notifier-2.4.0 test/rack_test.rb
hoptoad_notifier-2.3.12 test/rack_test.rb
hoptoad_notifier-2.3.11 test/rack_test.rb
hoptoad_notifier-2.3.10 test/rack_test.rb
hoptoad_notifier-2.3.9 test/rack_test.rb
hoptoad_notifier-2.3.8 test/rack_test.rb
hoptoad_notifier-2.3.7 test/rack_test.rb
riscfuture-hoptoad_notifier-2.3.6 test/rack_test.rb