Skip to content

Commit

Permalink
Add test for Hanami middleware not being installed
Browse files Browse the repository at this point in the history
Add a test that makes sure we don't install the middleware on the Hanami
app when AppSignal is not active.
  • Loading branch information
tombruijn committed Jun 25, 2024
1 parent e79d427 commit 3cc91d3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/lib/appsignal/integrations/hanami_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
describe "Hanami integration" do
require "appsignal/integrations/hanami"

before do
uninstall_hanami_middleware
end

def uninstall_hanami_middleware
middleware_stack = ::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX]
middleware_stack.delete_if do |middleware|
middleware.first == Appsignal::Rack::HanamiMiddleware ||
middleware.first == Rack::Events
end
end

describe Appsignal::Integrations::HanamiPlugin do
it "starts AppSignal on init" do
expect(Appsignal).to receive(:start)
Expand Down Expand Up @@ -37,6 +49,18 @@
expect(::Hanami::Action).to_not receive(:prepend)
.with(Appsignal::Integrations::HanamiIntegration)
end

it "does not add the middleware to the Hanami app" do
Appsignal::Integrations::HanamiPlugin.init

middleware_stack = ::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX]
expect(middleware_stack).to_not include(
[Rack::Events, [[kind_of(Appsignal::Rack::EventHandler)]], nil]
)
expect(middleware_stack).to_not include(
[Appsignal::Rack::HanamiMiddleware, [], nil]
)
end
end

context "when APPSIGNAL_APP_ENV ENV var is provided" do
Expand Down

0 comments on commit 3cc91d3

Please sign in to comment.