When I call a method on my object, one of the object's collaborator's attributes will change. I wanted to test this exchange by spying on the attribute's setter method, i.e. #baz=. But since the usual have_received(:baz=) doesn't work (#40), I have to verify the expectation via have_received.baz=(any_args) which yields false positives all the time.
A working example with false positives:
require 'rubygems'
require 'rspec'
require 'bogus/rspec'
class Bar
def baz=(x); end
end
class Foo
attr_reader :barable
def initialize(barable)
@barable = barable
end
def forward_something(x)
# barable.baz = x # disable to see whether the expectation works
end
end
describe Foo do
fake(:bar)
it "forwards setting something" do
foo = Foo.new(bar)
foo.forward_something(:stuff)
expect(bar).to have_received.baz=(any_args)
end
end
When I call a method on my object, one of the object's collaborator's attributes will change. I wanted to test this exchange by spying on the attribute's setter method, i.e.
#baz=
. But since the usualhave_received(:baz=)
doesn't work (#40), I have to verify the expectation viahave_received.baz=(any_args)
which yields false positives all the time.A working example with false positives: