diff --git a/spec/lib/appsignal/cli/install_spec.rb b/spec/lib/appsignal/cli/install_spec.rb index 2e6c7fde..ff64b320 100644 --- a/spec/lib/appsignal/cli/install_spec.rb +++ b/spec/lib/appsignal/cli/install_spec.rb @@ -631,7 +631,6 @@ def run it "completes the installation" do run - puts output expect(output).to include(*installation_instructions) expect(output).to include_complete_install end diff --git a/spec/lib/appsignal/hooks/activejob_spec.rb b/spec/lib/appsignal/hooks/activejob_spec.rb index 493d9cc9..d9c84fd7 100644 --- a/spec/lib/appsignal/hooks/activejob_spec.rb +++ b/spec/lib/appsignal/hooks/activejob_spec.rb @@ -76,39 +76,33 @@ ActiveJob::Base.queue_adapter = :inline start_agent(:options => options) - class ActiveJobTestJob < ActiveJob::Base + stub_const("ActiveJobTestJob", Class.new(ActiveJob::Base) do def perform(*_args) end - end + end) - class ActiveJobErrorTestJob < ActiveJob::Base + stub_const("ActiveJobErrorTestJob", Class.new(ActiveJob::Base) do def perform raise "uh oh" end - end + end) - class ActiveJobErrorWithRetryTestJob < ActiveJob::Base + stub_const("ActiveJobErrorWithRetryTestJob", Class.new(ActiveJob::Base) do retry_on StandardError, :wait => 0.seconds, :attempts => 2 def perform raise "uh oh" end - end + end) - class ActiveJobCustomQueueTestJob < ActiveJob::Base + stub_const("ActiveJobCustomQueueTestJob", Class.new(ActiveJob::Base) do queue_as :custom_queue def perform(*_args) end - end + end) end around { |example| keep_transactions { example.run } } - after do - Object.send(:remove_const, :ActiveJobTestJob) - Object.send(:remove_const, :ActiveJobErrorTestJob) - Object.send(:remove_const, :ActiveJobErrorWithRetryTestJob) - Object.send(:remove_const, :ActiveJobCustomQueueTestJob) - end it "reports the name from the ActiveJob integration" do tags = { :queue => queue } @@ -149,15 +143,12 @@ def perform(*_args) if DependencyHelper.rails_version >= Gem::Version.new("5.0.0") context "with priority" do before do - class ActiveJobPriorityTestJob < ActiveJob::Base + stub_const("ActiveJobPriorityTestJob", Class.new(ActiveJob::Base) do queue_with_priority 10 def perform(*_args) end - end - end - after do - Object.send(:remove_const, :ActiveJobPriorityTestJob) + end) end it "reports the priority as tag on the transaction" do @@ -264,16 +255,13 @@ def perform(*_args) if DependencyHelper.rails_version >= Gem::Version.new("5.0.0") context "with priority" do before do - class ActiveJobErrorPriorityTestJob < ActiveJob::Base + stub_const("ActiveJobErrorPriorityTestJob", Class.new(ActiveJob::Base) do queue_with_priority 10 def perform(*_args) raise "uh oh" end - end - end - after do - Object.send(:remove_const, :ActiveJobErrorPriorityTestJob) + end) end it "reports the priority as tag on the transaction" do @@ -370,31 +358,28 @@ def perform(*_args) context "with provider_job_id", :skip => DependencyHelper.rails_version < Gem::Version.new("5.0.0") do before do - module ActiveJob - module QueueAdapters + stub_const( + "ActiveJob::QueueAdapters::AppsignalTestAdapter", + Class.new(ActiveJob::QueueAdapters::InlineAdapter) do # Adapter used in our test suite to add provider data to the job # data, as is done by Rails provided ActiveJob adapters. # # This implementation is based on the # `ActiveJob::QueueAdapters::InlineAdapter`. - class AppsignalTestAdapter < InlineAdapter - def enqueue(job) - Base.execute(job.serialize.merge("provider_job_id" => "my_provider_job_id")) - end + def enqueue(job) + ActiveJob::Base.execute( + job.serialize.merge("provider_job_id" => "my_provider_job_id") + ) end end - end + ) - class ProviderWrappedActiveJobTestJob < ActiveJob::Base + stub_const("ProviderWrappedActiveJobTestJob", Class.new(ActiveJob::Base) do self.queue_adapter = :appsignal_test def perform(*_args) end - end - end - after do - ActiveJob::QueueAdapters.send(:remove_const, :AppsignalTestAdapter) - Object.send(:remove_const, :ProviderWrappedActiveJobTestJob) + end) end it "sets provider_job_id as tag" do @@ -409,31 +394,26 @@ def perform(*_args) context "with enqueued_at", :skip => DependencyHelper.rails_version < Gem::Version.new("6.0.0") do before do - module ActiveJob - module QueueAdapters + stub_const( + "ActiveJob::QueueAdapters::AppsignalTestAdapter", + Class.new(ActiveJob::QueueAdapters::InlineAdapter) do # Adapter used in our test suite to add provider data to the job # data, as is done by Rails provided ActiveJob adapters. # # This implementation is based on the # `ActiveJob::QueueAdapters::InlineAdapter`. - class AppsignalTestAdapter < InlineAdapter - def enqueue(job) - Base.execute(job.serialize.merge("enqueued_at" => "2020-10-10T10:10:10Z")) - end + def enqueue(job) + ActiveJob::Base.execute(job.serialize.merge("enqueued_at" => "2020-10-10T10:10:10Z")) end end - end + ) - class ProviderWrappedActiveJobTestJob < ActiveJob::Base + stub_const("ProviderWrappedActiveJobTestJob", Class.new(ActiveJob::Base) do self.queue_adapter = :appsignal_test def perform(*_args) end - end - end - after do - ActiveJob::QueueAdapters.send(:remove_const, :AppsignalTestAdapter) - Object.send(:remove_const, :ProviderWrappedActiveJobTestJob) + end) end it "sets queue time on transaction" do @@ -448,13 +428,10 @@ def perform(*_args) include ActionMailerHelpers before do - class ActionMailerTestJob < ActionMailer::Base + stub_const("ActionMailerTestJob", Class.new(ActionMailer::Base) do def welcome(_first_arg = nil, _second_arg = nil) end - end - end - after do - Object.send(:remove_const, :ActionMailerTestJob) + end) end context "without params" do @@ -524,15 +501,12 @@ def welcome(_first_arg = nil, _second_arg = nil) include ActionMailerHelpers before do - class ActionMailerTestMailDeliveryJob < ActionMailer::Base + stub_const("ActionMailerTestMailDeliveryJob", Class.new(ActionMailer::Base) do self.delivery_job = ActionMailer::MailDeliveryJob def welcome(*_args) end - end - end - after do - Object.send(:remove_const, :ActionMailerTestMailDeliveryJob) + end) end it "sets the Action mailer data on the transaction" do diff --git a/spec/lib/appsignal/hooks/celluloid_spec.rb b/spec/lib/appsignal/hooks/celluloid_spec.rb index 855d2ab7..2dab49b8 100644 --- a/spec/lib/appsignal/hooks/celluloid_spec.rb +++ b/spec/lib/appsignal/hooks/celluloid_spec.rb @@ -1,7 +1,7 @@ describe Appsignal::Hooks::CelluloidHook do context "with celluloid" do - before :context do - module Celluloid + before do + stub_const("Celluloid", Module.new do def self.shutdown @shut_down = true end @@ -9,12 +9,9 @@ def self.shutdown def self.shut_down? @shut_down == true end - end + end) Appsignal::Hooks::CelluloidHook.new.install end - after :context do - Object.send(:remove_const, :Celluloid) - end describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } @@ -22,11 +19,12 @@ def self.shut_down? it { is_expected.to be_truthy } end - specify { expect(Appsignal).to receive(:stop) } - specify { expect(Celluloid.shut_down?).to be true } - - after do - Celluloid.shutdown + describe "#install" do + it "calls Appsignal.stop on shutdown" do + expect(Appsignal).to receive(:stop) + Celluloid.shutdown + expect(Celluloid.shut_down?).to be true + end end end diff --git a/spec/lib/appsignal/hooks/data_mapper_spec.rb b/spec/lib/appsignal/hooks/data_mapper_spec.rb index 022191a1..dcf833ab 100644 --- a/spec/lib/appsignal/hooks/data_mapper_spec.rb +++ b/spec/lib/appsignal/hooks/data_mapper_spec.rb @@ -1,21 +1,12 @@ describe Appsignal::Hooks::DataMapperHook do context "with datamapper" do - before :context do - module DataMapper - end - - module DataObjects - class Connection - end - end + before do + stub_const("DataMapper", Module.new) + stub_const("DataObjects", Module.new) + stub_const("DataObjects::Connection", Class.new) Appsignal::Hooks::DataMapperHook.new.install end - after :context do - Object.send(:remove_const, :DataMapper) - Object.send(:remove_const, :DataObjects) - end - describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/delayed_job_spec.rb b/spec/lib/appsignal/hooks/delayed_job_spec.rb index 117b93c4..dbd0597a 100644 --- a/spec/lib/appsignal/hooks/delayed_job_spec.rb +++ b/spec/lib/appsignal/hooks/delayed_job_spec.rb @@ -1,21 +1,17 @@ describe Appsignal::Hooks::DelayedJobHook do context "with delayed job" do - before(:context) do - module Delayed - class Plugin - def self.callbacks - end + before do + stub_const("Delayed::Plugin", Class.new do + def self.callbacks end - - class Worker - def self.plugins - @plugins ||= [] - end + end) + stub_const("Delayed::Worker", Class.new do + def self.plugins + @plugins ||= [] end - end + end) + start_agent end - after(:context) { Object.send(:remove_const, :Delayed) } - before { start_agent } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/excon_spec.rb b/spec/lib/appsignal/hooks/excon_spec.rb index ac8de6e5..07160aa9 100644 --- a/spec/lib/appsignal/hooks/excon_spec.rb +++ b/spec/lib/appsignal/hooks/excon_spec.rb @@ -2,15 +2,14 @@ before { start_agent } context "with Excon" do - before(:context) do - class Excon + before do + stub_const("Excon", Class.new do def self.defaults @defaults ||= {} end - end + end) Appsignal::Hooks::ExconHook.new.install end - after(:context) { Object.send(:remove_const, :Excon) } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/gvl_spec.rb b/spec/lib/appsignal/hooks/gvl_spec.rb index b9fd5499..b5c1d427 100644 --- a/spec/lib/appsignal/hooks/gvl_spec.rb +++ b/spec/lib/appsignal/hooks/gvl_spec.rb @@ -32,14 +32,10 @@ def expect_gvltools_require end context "with old versions of GVLTools" do - before(:context) do - module GVLTools - VERSION = "0.1.0".freeze - end + before do + stub_const("GVLTools::VERSION", "0.1.0") end - after(:context) { Object.send(:remove_const, :GVLTools) } - before(:each) { expect_gvltools_require } describe "#dependencies_present?" do @@ -50,24 +46,19 @@ module GVLTools end context "with new versions of GVLTools" do - before(:context) do - module GVLTools - VERSION = "0.2.0".freeze - - module GlobalTimer - def self.enable - end + before do + stub_const("GVLTools", Module.new) + stub_const("GVLTools::VERSION", "0.2.0") + stub_const("GVLTools::GlobalTimer", Module.new do + def self.enable end - - module WaitingThreads - def self.enable - end + end) + stub_const("GVLTools::WaitingThreads", Module.new do + def self.enable end - end + end) end - after(:context) { Object.send(:remove_const, :GVLTools) } - describe "#dependencies_present?" do before(:each) { expect_gvltools_require } diff --git a/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb b/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb index 67f56ced..13732dbb 100644 --- a/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +++ b/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb @@ -7,19 +7,14 @@ allow(Appsignal::Hooks::MongoMonitorSubscriber).to receive(:new).and_return(subscriber) end - before(:context) do - module Mongo - module Monitoring - COMMAND = "command".freeze - - class Global - def subscribe - end - end + before do + stub_const("Mongo::Monitoring", Module.new) + stub_const("Mongo::Monitoring::COMMAND", "command") + stub_const("Mongo::Monitoring::Global", Class.new do + def subscribe end - end + end) end - after(:context) { Object.send(:remove_const, :Mongo) } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/passenger_spec.rb b/spec/lib/appsignal/hooks/passenger_spec.rb index 6bf96052..10e6f542 100644 --- a/spec/lib/appsignal/hooks/passenger_spec.rb +++ b/spec/lib/appsignal/hooks/passenger_spec.rb @@ -1,10 +1,8 @@ describe Appsignal::Hooks::PassengerHook do context "with passenger" do - before(:context) do - module PhusionPassenger - end + before do + stub_const("PhusionPassenger", Module.new) end - after(:context) { Object.send(:remove_const, :PhusionPassenger) } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/shoryuken_spec.rb b/spec/lib/appsignal/hooks/shoryuken_spec.rb index fd53e552..d06d2c5e 100644 --- a/spec/lib/appsignal/hooks/shoryuken_spec.rb +++ b/spec/lib/appsignal/hooks/shoryuken_spec.rb @@ -1,17 +1,13 @@ describe Appsignal::Hooks::ShoryukenHook do context "with shoryuken" do - before(:context) do - module Shoryuken + before do + stub_const("Shoryuken", Module.new do def self.configure_server end - end + end) Appsignal::Hooks::ShoryukenHook.new.install end - after(:context) do - Object.send(:remove_const, :Shoryuken) - end - describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/hooks/unicorn_spec.rb b/spec/lib/appsignal/hooks/unicorn_spec.rb index 35d3ae93..cbd761c7 100644 --- a/spec/lib/appsignal/hooks/unicorn_spec.rb +++ b/spec/lib/appsignal/hooks/unicorn_spec.rb @@ -1,30 +1,27 @@ describe Appsignal::Hooks::UnicornHook do context "with unicorn" do - before :context do - module Unicorn - class HttpServer - def worker_loop(_worker) - @worker_loop = true - end - - def worker_loop? - @worker_loop == true - end + before do + stub_const("Unicorn", Module.new) + stub_const("Unicorn::HttpServer", Class.new do + def worker_loop(_worker) + @worker_loop = true end - class Worker - def close - @close = true - end + def worker_loop? + @worker_loop == true + end + end) + stub_const("Unicorn::Worker", Class.new do + def close + @close = true + end - def close? - @close == true - end + def close? + @close == true end - end + end) Appsignal::Hooks::UnicornHook.new.install end - after(:context) { Object.send(:remove_const, :Unicorn) } describe "#dependencies_present?" do subject { described_class.new.dependencies_present? } diff --git a/spec/lib/appsignal/integrations/data_mapper_spec.rb b/spec/lib/appsignal/integrations/data_mapper_spec.rb index 1e4de9e7..0b0fd58e 100644 --- a/spec/lib/appsignal/integrations/data_mapper_spec.rb +++ b/spec/lib/appsignal/integrations/data_mapper_spec.rb @@ -1,11 +1,6 @@ require "appsignal/integrations/data_mapper" describe Appsignal::Hooks::DataMapperLogListener do - module DataMapperLog - def log(message) - end - end - describe "#log" do let(:transaction) { http_request_transaction } let(:message) do @@ -14,17 +9,12 @@ def log(message) :duration => 100_000_000 # nanoseconds ) end - let(:connection_class) do - module DataObjects - module Sqlite3 - class Connection - include DataMapperLog - include Appsignal::Hooks::DataMapperLogListener - end - end - end - end before do + stub_const("DataMapperLog", Module.new do + def log(message) + end + end) + stub_const("DataObjects", Module.new) start_agent set_current_transaction(transaction) end @@ -34,28 +24,35 @@ def log_message connection_class.new.log(message) end - it "records the log entry in an event" do - log_message + context "when the scheme is SQL-like" do + let(:connection_class) { DataObjects::Sqlite3::Connection } + before do + stub_const("DataObjects::Sqlite3::Connection", Class.new do + include DataMapperLog + include Appsignal::Hooks::DataMapperLogListener + end) + end - expect(transaction).to include_event( - "name" => "query.data_mapper", - "title" => "DataMapper Query", - "body" => "SELECT * from users", - "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT, - "duration" => 100.0 - ) + it "records the log entry in an event" do + log_message + + expect(transaction).to include_event( + "name" => "query.data_mapper", + "title" => "DataMapper Query", + "body" => "SELECT * from users", + "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT, + "duration" => 100.0 + ) + end end - context "when the scheme is not sql-like" do - let(:connection_class) do - module DataObjects - module MongoDB - class Connection - include DataMapperLog - include Appsignal::Hooks::DataMapperLogListener - end - end - end + context "when the scheme is not SQL-like" do + let(:connection_class) { DataObjects::MongoDB::Connection } + before do + stub_const("DataObjects::MongoDB::Connection", Class.new do + include DataMapperLog + include Appsignal::Hooks::DataMapperLogListener + end) end it "records the log entry in an event without body" do diff --git a/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb b/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb index 29144d9d..19e9ee22 100644 --- a/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +++ b/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb @@ -1,22 +1,19 @@ describe "Appsignal::Integrations::DelayedJobHook" do - before(:context) do - module Delayed - class Plugin - def self.callbacks - end + let(:options) { {} } + before do + stub_const("Delayed", Module.new) + stub_const("Delayed::Plugin", Class.new do + def self.callbacks end - - class Worker - def self.plugins - @plugins ||= [] - end + end) + stub_const("Delayed::Worker", Class.new do + def self.plugins + @plugins ||= [] end - end + end) require "appsignal/integrations/delayed_job_plugin" + start_agent(:options => options) end - after(:context) { Object.send(:remove_const, :Delayed) } - let(:options) { {} } - before { start_agent(:options => options) } # We haven't found a way to test the hooks, we'll have to do that manually diff --git a/spec/lib/appsignal/integrations/object_spec.rb b/spec/lib/appsignal/integrations/object_spec.rb index 3016bfca..a8a27d12 100644 --- a/spec/lib/appsignal/integrations/object_spec.rb +++ b/spec/lib/appsignal/integrations/object_spec.rb @@ -87,14 +87,13 @@ def splat(*args, **kwargs) context "with named class" do before do - class NamedClass + stub_const("NamedClass", Class.new do def foo 1 end appsignal_instrument_method :foo - end + end) end - after { Object.send(:remove_const, :NamedClass) } let(:klass) { NamedClass } it "instruments the method and calls it" do @@ -106,18 +105,13 @@ def foo context "with nested named class" do before do - module MyModule - module NestedModule - class NamedClass - def bar - 2 - end - appsignal_instrument_method :bar - end + stub_const("MyModule::NestedModule::NamedClass", Class.new do + def bar + 2 end - end + appsignal_instrument_method :bar + end) end - after { Object.send(:remove_const, :MyModule) } let(:klass) { MyModule::NestedModule::NamedClass } it "instruments the method and calls it" do @@ -257,14 +251,13 @@ def self.splat(*args, **kwargs) context "with named class" do before do - class NamedClass + stub_const("NamedClass", Class.new do def self.bar 2 end appsignal_instrument_class_method :bar - end + end) end - after { Object.send(:remove_const, :NamedClass) } let(:klass) { NamedClass } it "instruments the method and calls it" do @@ -276,18 +269,13 @@ def self.bar context "with nested named class" do before do - module MyModule - module NestedModule - class NamedClass - def self.bar - 2 - end - appsignal_instrument_class_method :bar - end + stub_const("MyModule::NestedModule::NamedClass", Class.new do + def self.bar + 2 end - end + appsignal_instrument_class_method :bar + end) end - after { Object.send(:remove_const, :MyModule) } let(:klass) { MyModule::NestedModule::NamedClass } it "instruments the method and calls it" do diff --git a/spec/lib/appsignal/integrations/resque_spec.rb b/spec/lib/appsignal/integrations/resque_spec.rb index ec4397ac..df5da1c9 100644 --- a/spec/lib/appsignal/integrations/resque_spec.rb +++ b/spec/lib/appsignal/integrations/resque_spec.rb @@ -14,26 +14,22 @@ def perform_rescue_job(klass, options = {}) before do start_agent(:options => options) - class ResqueTestJob + stub_const("ResqueTestJob", Class.new do def self.perform(*_args) end - end + end) - class ResqueErrorTestJob + stub_const("ResqueErrorTestJob", Class.new do def self.perform raise "resque job error" end - end + end) expect(Appsignal).to receive(:stop) # Resque calls stop after every job end around do |example| keep_transactions { example.run } end - after do - Object.send(:remove_const, :ResqueTestJob) - Object.send(:remove_const, :ResqueErrorTestJob) - end it "tracks a transaction on perform" do perform_rescue_job(ResqueTestJob) diff --git a/spec/lib/appsignal/integrations/sidekiq_spec.rb b/spec/lib/appsignal/integrations/sidekiq_spec.rb index 0c5ddb7d..b9329290 100644 --- a/spec/lib/appsignal/integrations/sidekiq_spec.rb +++ b/spec/lib/appsignal/integrations/sidekiq_spec.rb @@ -526,20 +526,20 @@ def expect_transaction_to_have_sidekiq_event(transaction) Appsignal.internal_logger = test_logger(log) ActiveJob::Base.queue_adapter = :sidekiq - class ActiveJobSidekiqTestJob < ActiveJob::Base + stub_const("ActiveJobSidekiqTestJob", Class.new(ActiveJob::Base) do self.queue_adapter = :sidekiq def perform(*_args) end - end + end) - class ActiveJobSidekiqErrorTestJob < ActiveJob::Base + stub_const("ActiveJobSidekiqErrorTestJob", Class.new(ActiveJob::Base) do self.queue_adapter = :sidekiq def perform(*_args) raise "uh oh" end - end + end) # Manually add the AppSignal middleware for the Testing environment. # It doesn't use configured middlewares by default looks like. # We test somewhere else if the middleware is installed properly. @@ -547,10 +547,6 @@ def perform(*_args) chain.add Appsignal::Integrations::SidekiqMiddleware end end - after do - Object.send(:remove_const, :ActiveJobSidekiqTestJob) - Object.send(:remove_const, :ActiveJobSidekiqErrorTestJob) - end it "reports the transaction from the ActiveJob integration" do perform_sidekiq_job(ActiveJobSidekiqTestJob, given_args) diff --git a/spec/lib/appsignal/rack/grape_middleware_spec.rb b/spec/lib/appsignal/rack/grape_middleware_spec.rb index e6741198..0980ea65 100644 --- a/spec/lib/appsignal/rack/grape_middleware_spec.rb +++ b/spec/lib/appsignal/rack/grape_middleware_spec.rb @@ -19,12 +19,12 @@ end let(:middleware) { Appsignal::Rack::GrapeMiddleware.new(api_endpoint) } let(:transaction) { http_request_transaction } - before { start_agent } + before do + stub_const("GrapeExample::Api", app) + start_agent + end around do |example| - GrapeExample = Module.new - GrapeExample.send(:const_set, :Api, app) keep_transactions { example.run } - Object.send(:remove_const, :GrapeExample) end def make_request(env) diff --git a/spec/lib/appsignal_spec.rb b/spec/lib/appsignal_spec.rb index 11de4496..c75713a7 100644 --- a/spec/lib/appsignal_spec.rb +++ b/spec/lib/appsignal_spec.rb @@ -520,10 +520,7 @@ def on_start describe ".load" do before do - TestLoader = define_loader(:appsignal_loader) - end - after do - Object.send(:remove_const, :TestLoader) + stub_const("TestLoader", define_loader(:appsignal_loader)) end it "loads a loader" do diff --git a/spec/lib/puma/appsignal_spec.rb b/spec/lib/puma/appsignal_spec.rb index 46d45497..e7d5919e 100644 --- a/spec/lib/puma/appsignal_spec.rb +++ b/spec/lib/puma/appsignal_spec.rb @@ -100,7 +100,7 @@ def track_message(message) let(:expected_default_tags) { { "hostname" => hostname } } let(:stats_data) { { :backlog => 1 } } before do - module Puma + stub_const("Puma", Module.new do def self.stats JSON.dump(@_stats_data) end @@ -112,30 +112,26 @@ def self.stats_hash def self._set_stats=(data) @_stats_data = data end - - class Plugin - class << self - attr_reader :appsignal_plugin - - def create(&block) - @appsignal_plugin = Class.new(::Puma::Plugin) - @appsignal_plugin.class_eval(&block) - end + end) + stub_const("Puma::Plugin", Class.new do + class << self + attr_reader :appsignal_plugin + + def create(&block) + @appsignal_plugin = Class.new(::Puma::Plugin) + @appsignal_plugin.class_eval(&block) end + end - attr_reader :in_background_block + attr_reader :in_background_block - def in_background(&block) - @in_background_block = block - end + def in_background(&block) + @in_background_block = block end - end + end) load File.expand_path("../lib/puma/plugin/appsignal.rb", APPSIGNAL_SPEC_DIR) end - after do - Object.send(:remove_const, :Puma) - Object.send(:remove_const, :AppsignalPumaPlugin) - end + after { Object.send(:remove_const, :AppsignalPumaPlugin) } def run_plugin(stats_data, plugin, &block) Puma._set_stats = stats_data