I am experiencing some baffling behavior in rspec and rspec-rails 2.11.0. I have reproduced the behavior on a co-worker's app running 2.7.1 (both on ruby 1.9.3)
These tests work as expected (fails):
it "should not change i" do
i = 0
expect {
i = 2
}.not_to change { i }
end
it "should not change i" do
i = 0
expect {
i = 2
}.not_to change { i }.from( 0 )
end
Failure message is "result should not have changed, but did change from 0 to 2" in both cases
Changing the "from" in the expectation to a different value inexplicably makes it pass, rather than fail no matter what happens to the value of i in the expect block:
it "should not change i" do
i = 0
expect {
i = 2
}.not_to change { i }.from( 1 )
end
I've only recently upgraded to 1.9.3 and I can say with some certainty I would have noticed this behavior before if I had been experiencing it. Can anyone explain this and/or what I'm doing wrong?