-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate rspec-mocks incompatibility with add_method_tracer
#2695
Comments
The example above was created with this class: # lib/bowling.rb
require 'newrelic_rpm'
class Bowling
attr_reader :score
def initialize
@score = 0
end
def hit(pin_count)
@score += pin_count
end
add_method_tracer :hit
end And this spec: # spec/bowling_spec.rb
require 'bowling'
RSpec.describe Bowling, "#score" do
context "with no strikes or spares" do
# passes
it "sums the pin count for each roll" do
bowling = Bowling.new
20.times { bowling.hit(4) }
expect(bowling.score).to eq 80
end
# fails with error
it "does not like to be prepended" do
allow_any_instance_of(Bowling)
.to receive(:hit)
.and_return(300)
end
end
end With this Gemfile: source 'https://rubygems.org'
gem "newrelic_rpm", "~> 9.10"
gem "rspec", "~> 3.13" The example was drawn from: https://rspec.info/ |
add_method_tracer
allow_any_instance_of
incompatibility with add_method_tracer
allow_any_instance_of
incompatibility with add_method_tracer
add_method_tracer
The agent needs to be able to add method tracers in cases where the API is invoked before the agent is loaded. This means the behavior of We have a feature request open that may get around this. #2701 would allow method tracers to be added by configuration rather than declaring them directly in your code. For anyone who encounters this problem, we have a few workarounds to recommend:
Option A: let(:bowling) do
b = bowling.new
allow(b).to receive(:hit).and_return(100)
b
end Option B: let(:bowling) { Bowling.new }
before do
allow(bowling)
.to receive(:hit)
.and_return(100)
end
class Module; def add_method_tracer(*_args); end; end |
When
add_method_tracer
is used on a method that is overridden in an RSpec test usingallow_any_instance_of
, the following error is raised:add_method_tracer
prepends onto the methods it traces to create segments and metrics.This error occurs even when the
:agent_enabled
configuration is set tofalse
.A customer reported they would like to use
add_method_tracer
andallow_any_instance_of
on the same method.The text was updated successfully, but these errors were encountered: