Sha256: b7adea229f090e043140b13975d7c8947904831973c9201945083f6afd7e32e8

Contents?: true

Size: 1.78 KB

Versions: 59

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe Appsignal::Rack::Instrumentation do
  before :all do
    start_agent
    @events = []
    @subscriber = ActiveSupport::Notifications.subscribe do |*args|
      @events << ActiveSupport::Notifications::Event.new(*args)
    end
  end
  after :all do
    ActiveSupport::Notifications.unsubscribe(@subscriber)
  end

  let(:app) { double(:call => true) }
  let(:env) { {} }
  let(:middleware) { Appsignal::Rack::Instrumentation.new(app, {}) }

  describe "#call" do
    it "should instrument the call" do
      app.should_receive(:call).with(env)
      middleware.stub(:raw_payload => {})

      middleware.call(env)

      @events.last.name.should == 'process_action.rack'
    end
  end

  describe "raw_payload" do
    let(:env) do
      {
        'rack.input' => StringIO.new,
        'REQUEST_METHOD' => 'GET',
        'PATH_INFO' => '/homepage',
        'QUERY_STRING' => 'param=something'
      }
    end
    subject { middleware.raw_payload(env) }

    it { should == {
      :action => 'GET:/homepage',
      :params => {'param' => 'something'},
      :method => 'GET',
      :path => '/homepage'
    } }
  end

  describe "use a custom request class and parameters method" do
    let(:request_class) do
      double(
        new: double(
          request_method: 'POST',
          path: '/somewhere',
          filtered_params: {'param' => 'changed_something'}
        )
      )
    end
    let(:options) do
      { request_class: request_class, params_method: :filtered_params }
    end
    let(:middleware) { Appsignal::Rack::Instrumentation.new(app, options) }
    subject { middleware.raw_payload(env) }

    it { should == {
      :action => 'POST:/somewhere',
      :params => {'param' => 'changed_something'},
      :method => 'POST',
      :path => '/somewhere'
    } }
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
appsignal-0.11.18 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.11.17 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.11.16 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.11.15 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.11.14 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.11.14.beta.1 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.31 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.30 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.29 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.28 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.27 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.26 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.25 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.24 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.23 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.22 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.21 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.20 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.19 spec/lib/appsignal/rack/instrumentation_spec.rb
appsignal-0.12.beta.18 spec/lib/appsignal/rack/instrumentation_spec.rb