SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Yorkshire, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy assert_not_nil assigns(:story) error p186 Simple Rails 2, Help!

    Working through Simple Rails 2, on page 186 "Testing the Controller"

    for the code:
    Code Ruby:
    def test_should_show_index
      get :index
      assert_response :success
      assert_template 'index'
      assert_not_nil assigns(:story)
    end

    The last line
    Code Ruby:
    assert_not_nil assigns(:story)
    gives me the error:
    "...... <nil> expected to not be nil"
    when i run "rake test:functionals"

    The code works perfectly when i call it from a web browser.

    I don't really understand what's going on. Any ideas, suggestions?

    Thanks
    Afuera
    Last edited by afuera; Jul 10, 2008 at 11:53. Reason: added ruby highlighting

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't own that book but shouldn't it be :stories instead of :story if you're testing the index page?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Yorkshire, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    I don't own that book but shouldn't it be :stories instead of :story if you're testing the index page?
    No, at this point in the tutorial the index page only returns one record


    Any other ideas??

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe there's an error in your fixtures?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Yorkshire, UK
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh!

    While playing around with the code I'd given the instance variable referenced in "assert_not_nil assignsstory)" a different name so it would be nil! Schoolboy error

    Thanks for your suggestions Fenrir2

    afuera


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •