I have read what the RSpec manual says about the difference, but some things are still confusing. Every other source, including “The RSpec Book” only explain about “let”, and “The Rails 3 Way” is just as confusing as the manual.
I understand that “let” is only evaluated when invoked, and keeps the same value within a scope. So it makes sense that in the first example in the manual the first test passes as the “let” is invoked only once, and the second test passes as it adds to the value of the first test (which was evaluated once in the first test and has the value of 1).
Following that, since “let!” evaluates when defined, and again when invoked, should the test not fail as “count.should eq(1)” should have instead be “count.should eq(2)”?
Any help would be appreciated.
It’s not invoked when defined, but rather before each example (and then it’s memoized and not invoked again by the example). This way, count will have a value of 1.
Anyway, if you have another example, the before hook is invoked again – all of the following tests pass: