Sha256: 211d3c91956f5c9a774192408c60371b78dd3650b235d628763787fb8c3b0cb7

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'captivus/rails_capturer'

describe Captivus::RailsCapturer do
  describe "call" do
    before do
      @app = double 'app'
      @rails_capturer = Captivus::RailsCapturer.new @app
    end

    it "calls the app with the given env" do
      env = double 'env'
      result = double 'result'
      @app.stub(:call).with(env) { result }
      expect(@rails_capturer.call(env)).to eq result
    end

    context "when calling the app raises an error" do
      before do
        @app.stub(:call) { raise Exception, 'Error raised' }
        @env = {'action_controller.instance' => double('controller',
          :controller_name => 'widgets',
          :action_name => 'show',
          :request => double('request', :filtered_parameters => {
            'controller' => 'widgets',
            'action' => 'show',
            'p1' => 'v1',
            'p2' => 'v2'
          })
        )}
      end

      it "tells Captivus to notify of the exception" do
        Captivus.should_receive(:notify).with kind_of(Exception), 'context' => {
          'controller' => 'widgets',
          'action' => 'show',
          'params' => {'p1' => 'v1', 'p2' => 'v2'}
        }
        begin
          @rails_capturer.call @env
        rescue Exception
        end
      end

      it "raises the error" do
        expect { @rails_capturer.call @env }.to raise_error Exception, "Error raised"
      end
    end

    context "when calling the app does not raise an error" do
      before { @app.stub :call }

      it "does not notify the Captivus API" do
        @rails_capturer.call double('env')
        expect(captivus_api.requests.size).to eq 0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
captivus-0.0.6 spec/captivus/rails_capturer_spec.rb
captivus-0.0.5 spec/captivus/rails_capturer_spec.rb