Skip to content

Commit

Permalink
Stub constants in specs (#1286)
Browse files Browse the repository at this point in the history
Follow-up of previous commits.

Instead of defining constants and manually removing them with
`remove_const` (which wasn't done here) use the built-in RSpec helper
`stub_const`. This will prevent constants from leaking into other specs.
  • Loading branch information
tombruijn authored Sep 4, 2024
1 parent 390909b commit 7e3b1d1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ def self.appsignal_name
end

context "for a struct" do
before :context do
TestStruct = Struct.new(:key)
end
let(:struct) { TestStruct.new("value") }
let(:struct_class) { Struct.new(:key) }
let(:struct) { struct_class.new("value") }

context "when the key exists" do
subject { plugin.extract_value(struct, :key) }
Expand All @@ -369,16 +367,16 @@ def self.appsignal_name
end

context "for a struct with a method" do
before :context do
class TestStructClass < Struct.new(:id) # rubocop:disable Style/StructInheritance
before do
stub_const("TestStructClass", Class.new(Struct.new(:id)) do
def appsignal_name
"TestStruct#perform"
end

def bool_false
false
end
end
end)
end
let(:struct) { TestStructClass.new("id") }

Expand Down

0 comments on commit 7e3b1d1

Please sign in to comment.