Sha256: 1dffa068678c21f53ee4796df87d96a62756c06d98f1e641136c9ab4306a9022

Contents?: true

Size: 1.99 KB

Versions: 174

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Appsignal::Rack::JSExceptionCatcher do
  let(:app)            { double(:call => true) }
  let(:options)        { double }
  let(:active)         { true }
  let(:config_options) { {:enable_frontend_error_catching => true} }
  let(:config)         { project_fixture_config('production', config_options) }

  before do
    Appsignal.stub(:config => config)
    config.stub(:active? => active)
  end

  describe "#initialize" do
    it "should log to the logger" do
      expect( Appsignal.logger ).to receive(:debug)
        .with('Initializing Appsignal::Rack::JSExceptionCatcher')

      Appsignal::Rack::JSExceptionCatcher.new(app, options)
    end
  end

  describe "#call" do
    let(:catcher) { Appsignal::Rack::JSExceptionCatcher.new(app, options) }

    context "when path is not `/appsignal_error_catcher`" do
      let(:env) { {'PATH_INFO' => '/foo'} }

      it "should call the next middleware" do
        expect( app ).to receive(:call).with(env)
      end
    end

    context "when path is `/appsignal_error_catcher`" do
      let(:transaction) { double(:complete! => true) }
      let(:env) do
        {
          'PATH_INFO'  => '/appsignal_error_catcher',
          'rack.input' => double(:read => '{"foo": "bar"}')
        }
      end

      it "should create a JSExceptionTransaction" do
        expect( Appsignal::JSExceptionTransaction ).to receive(:new)
          .with({'foo' => 'bar'})
          .and_return(transaction)

        expect( transaction ).to receive(:complete!)
      end

      context "when `frontend_error_catching_path` is different" do
        let(:config_options) do
          {
            :frontend_error_catching_path   => '/foo'
          }
        end

        it "should not create a transaction" do
          expect( Appsignal::JSExceptionTransaction ).to_not receive(:new)
        end

        it "should call the next middleware" do
          expect( app ).to receive(:call).with(env)
        end
      end
    end

    after { catcher.call(env) }
  end

end

Version data entries

174 entries across 174 versions & 1 rubygems

Version Path
appsignal-0.12.beta.6 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.5 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.4 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.3 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.2 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.1 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.11 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.12.beta.0 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.10 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.10.beta.2 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.10.beta.1 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.9 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.8.beta.4 spec/lib/appsignal/rack/js_exception_catcher_spec.rb
appsignal-0.11.8.beta.3 spec/lib/appsignal/rack/js_exception_catcher_spec.rb