I donβt think it does what you expect, but the way the test is written doesn't really reveal it. Your last value fails because it has never been defined as 1.
The main step in identifying this is inverting the test.
describe "stuff" do it "should not change i" do i = 0 expect { i = 2 }.to change { i } end it "should not change i" do i = 0 expect { i = 2 }.to change { i }.from( 0 ) end it "should not change i" do i = 0 expect { i = 2 }.to change { i }.from( 1 ) end end
This causes the first two tests to pass, and the last test with an error result should have initially been 1, but was 0
So, if we take the test test as is, you say: i should not change from 1 , and since I will never be 1, this test will never end.
it "should not change i" do i = 0 expect { i = 2 }.not_to change { i }.from( 1 )
source share