Skip to content

Commit

Permalink
Test webmachine custom action names
Browse files Browse the repository at this point in the history
Use a Webmachine resource to test the instrumentation. Use that to set a
custom action name and test that it doesn't get overwritten by the
instrumentation.
  • Loading branch information
tombruijn committed Jul 2, 2024
1 parent d24921c commit 1d3aaeb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
9 changes: 5 additions & 4 deletions gemfiles/webmachine1.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'webmachine', '~> 1.6'
gem 'webrick'
gem "i18n", "~> 0.0" # Lock to pre 1.x version as it's not compatible
gem "webmachine", "~> 1.6"
gem "webrick"

gemspec :path => '../'
gemspec :path => "../"
47 changes: 37 additions & 10 deletions spec/lib/appsignal/integrations/webmachine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,26 @@ def headers
nil
)
end
let(:resource) { double(:trace? => false, :handle_exception => true, :"code=" => nil) }
let(:response) { Response.new }
let(:fsm) { Webmachine::Decision::FSM.new(resource, request, response) }
let(:app) do
proc do
def to_html
"Some HTML"
end
end
end
let(:resource) do
app_block = app
Class.new(Webmachine::Resource) do
class_eval(&app_block) if app_block

def self.name
"MyResource"
end
end
end
let(:resource_instance) { resource.new(request, response) }
let(:response) { Webmachine::Response.new }
let(:fsm) { Webmachine::Decision::FSM.new(resource_instance, request, response) }
before { start_agent }
around { |example| keep_transactions { example.run } }

Expand All @@ -35,7 +52,23 @@ def headers

it "sets the action" do
fsm.run
expect(last_transaction).to have_action("RSpec::Mocks::Double#GET")
expect(last_transaction).to have_action("MyResource#GET")
end

context "with action already set" do
let(:app) do
proc do
def to_html
Appsignal.set_action("Custom Action")
"Some HTML"
end
end
end

it "doesn't overwrite the action" do
fsm.run
expect(last_transaction).to have_action("Custom Action")
end
end

it "records an instrumentation event" do
Expand All @@ -53,12 +86,6 @@ def headers
expect(last_transaction).to be_completed
expect(current_transaction?).to be_falsy
end

it "sets a response code" do
expect(fsm.response.code).to be_nil
fsm.run
expect(fsm.response.code).not_to be_nil
end
end

describe "#handle_exceptions" do
Expand Down

0 comments on commit 1d3aaeb

Please sign in to comment.