Reputation: 1827
I have that rspec test
let(:document) { Document.new }
let(:residue) { Residue.new }
describe "inner_residue=" do
before do
document.producer_residue = residue
end
it 'dont changes the producer residue' do
expect { document.inner_residue = residue }.to_not change(document, :producer_residue)
end
end
That outputs this error:
producer_residue should not have changed, but did change from #<Residue id: nil, un_code: nil, description: "res", created_at: ... > to #<Residue id: nil, un_code: nil, description: "res", created_at: ... >
As you see, there is the same residue. The method its more complicated, but this one is a simplication that fails too:
def inner_residue=(other)
return self.producer_residue = self.addressee_residue = nil unless other
self.producer_residue = producer_residue
end
So... WTF?
Changing a residue for itself makes the assertion fails? I've checked if they are the same residue with ==, ===, eq? an its always true. I can't understand whats wrong with this.
I'm using rspec 1.3 (its an rails 2.3 app, I cant upgrade to rspec2)
Upvotes: 0
Views: 198
Reputation: 9000
RSpec has no problem with objects that are equal. The problem here is that in ActiveRecord, two unsaved models are not considered equal, even if they have all the same properties. You can see this if you run puts (Residue.new == Residue.new)
.
You'll have to save the Residue object for this to work.
Upvotes: 2