What is happening when your code runs fine, the tutorial shows that your code should be "RSpec green", but it isn't? 

For me, it's time to go to StackOverflow.com again.  The hardest part was searching for the right answer.  But once it was found, it just works!

So, for those of you stuck in (Michael Hartl's awesome Rails Tutorial) chapter 10 and wondering why you now have RSpec giving you 7-10 errors, don't worry!

I had suspected all along that this was just one of the differences between Rails 3.0 and Rails 3.1, and it appears that I was right!  When searching for "test_sign_in" the 4th hit took me here, and the answer redirected me here, where I received the bizarre but efficient changes that needed to be made.

In sessions_helper, find def sign_in
  • old:
    current_user = user
  • new:
    current_user = user
    @current_user = user
Also in sessions_helper, find def sign_out
  • old:
    current_user = nil
  • new:
    current_user = nil
    @current_user = nil
Even the author is left guessing why this works.  But it's small, efficient, and keeps the tests nice and small.  After all, each test should test one and only one thing, right?!


[TDD = Test Driven Development]
 
 
RSpec seems to make such intuitive sense, and now that I've started to wrap my head around TDD, I am starting to see the benefit.  Sure, initial development may be slower, but the overall development approach should help over the long-term maintenance of your code.

But then, RSpec completely stumped me. 

Thanks to the folks at StackOverflow, because this post, explains my problem exactly.  After multiple tries, my test just wouldn't work.  But with this explanation, I started wondering how the "click_link ...." test was working.  Then it hit me:  each "click_link" represents a user click, so the following test is now looking at the new page (just "clicked") and not the path I had specified above.  AHA!

Very interesting (and, sadly, unintuitive for the newbie).