Sha256: 39a3414e268ab33d6ce016898687a4325504ed7ac3bc3cc4aca36cdd20ab0336

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe YogiBerra::ExceptionMiddleware do
  before(:each) do
    YogiBerra::Logger.stub(:log)
    load "#{SPEC_FOLDER}/fixtures/rails.rb"
  end

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

    response = stack.call(environment)

    response[0].should == 'response'
    response[1].should == {}
    response[2].instance_variable_get("@response").should == { 'key' => 'value' }
  end

  it "deliver an exception raised while calling an upstream app" do
    mock_mongo_client(true, true)
    exception = build_exception
    environment = { 'key' => 'value' }
    app = lambda do |env|
      raise exception
    end

    begin
      stack = YogiBerra::ExceptionMiddleware.new(app)
      stack.call(environment)
    rescue Exception => raised
      raised.should == exception
    end
  end

  it "should deliver an exception in rack.exception" do
    mock_mongo_client(true, true)
    exception = build_exception
    environment = { 'key' => 'value' }

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

    actual_response = stack.call(environment)

    actual_response[0].should == 200
    actual_response[1].should == {}
    actual_response[2].instance_variable_get("@response").should == ["okay"]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yogi_berra-0.0.14 spec/yogi_berra_exception_middleware_spec.rb
yogi_berra-0.0.13 spec/yogi_berra_exception_middleware_spec.rb
yogi_berra-0.0.12 spec/yogi_berra_exception_middleware_spec.rb
yogi_berra-0.0.11 spec/yogi_berra_exception_middleware_spec.rb