我有那个 rspec 测试
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
输出此错误:
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: ... >
如您所见,有相同的残留物。该方法更复杂,但这也是一种失败的简单方法:
def inner_residue=(other)
return self.producer_residue = self.addressee_residue = nil unless other
self.producer_residue = producer_residue
end
所以... WTF?
为自己更改残基会使断言失败?我检查了它们是否与 ==、===、eq 相同?它总是正确的。我不明白这有什么问题。
我正在使用 rspec 1.3(它是一个 rails 2.3 应用程序,我无法升级到 rspec2)