SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Chapter 8 Test suite problems

    Hi

    I'm having a bit of trouble with the test suite at the end of chapter 8 in ROR.

    I have built the application as directed, written all the tests and check them against the code archive but I am getting errors and failurs spewing out at me.

    Is there a problem with the actual code for this section that hasn't been picked up??

    I've uploaded the results of my rake test for you to look at, if it helps or not.
    Attached Files Attached Files

  2. #2
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have mananged to sort out a couple of the issues

    I now get 4 failures and 4 errors after a rake test on the application.

    1) Failure:
    test_should_redirect_after_login_with_return_url(AccountControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:86:in `assert_redirected_to'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:35:in `assert_redirected_to'
    ./test/functional/account_controller_test.rb:39:in `test_should_redirect_after_login_with_return_url']:
    response is not a redirection to all of the options supplied (redirection is <{"controller"=>"story"}>), difference: <{"action"=>"new"}>

    2) Error:
    test_should_accept_vote(StoryControllerTest):
    StandardError: No fixture with name 'another' found for table 'stories'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/fixtures.rb:491:in `stories'
    ./test/functional/story_controller_test.rb:65:in `test_should_accept_vote'

    3) Error:
    test_should_add_story(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.new_record?
    ./test/functional/story_controller_test.rb:40:in `test_should_add_story'

    4) Failure:
    test_should_indicate_logged_in_user(StoryControllerTest) [./test/functional/story_controller_test.rb:99]:
    <#<User:0x2b133b623b70
    @attributes=
    {"name"=>"Paul Gisbourne",
    "id"=>"1",
    "password"=>"phili121",
    "login"=>"paulgis",
    "email"=>"paul_gis@hotmail.com"}>> expected but was
    <nil>.

    5) Error:
    test_should_reject_missing_story_attribute(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.errors
    ./test/functional/story_controller_test.rb:47:in `test_should_reject_missing_story_attribute'

    6) Failure:
    test_should_show_new(StoryControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:26:in `assert_response'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:18:in `assert_response'
    ./test/functional/story_controller_test.rb:25:in `test_should_show_new']:
    Expected response to be a <:success>, but was <302>

    7) Failure:
    test_should_show_new_form(StoryControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/selector_assertions.rb:281:in `assert_select'
    ./test/functional/story_controller_test.rb:32:in `test_should_show_new_form']:
    Expected at least 3 elements, found 0.
    <false> is not true.

    8) Error:
    test_should_store_user_with_story(StoryControllerTest):
    NoMethodError: You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.user
    ./test/functional/story_controller_test.rb:114:in `test_should_store_user_with_story'

    21 tests, 42 assertions, 4 failures, 4 errors
    Really hope you guys can help me in this, I have spent quite a bit of time checking my code against the book and the code archive, both of which appear spot on.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the code is good, maybe your db schema is wrong?

  4. #4
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply,

    I will take a look at the db schema when I get a few free hours.....

  5. #5
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a quick query,

    has anyone else had problems with the test at the end of chapter 8?

  6. #6
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problems with assert_select in general

    I'm having issues with assert_select in general. I'm only through chapter seven, but both tests that use it so far are failing. I have also tried writing my own tests even following is failing which if I understand how to use the command should pass for a page with any tags on it.

    assert_select '*', true

  7. #7
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have checked that I am running rail 1.2.3 using "rails -v" and in config/environment.rb.

  8. #8
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using actionpack 1.13.3. I'm seeing that in the failure message.

  9. #9
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Testing answers and questions

    2) Error:
    test_should_accept_vote(StoryControllerTest):
    StandardError: No fixture with name 'another' found for table 'stories'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/fixtures.rb:491:in `stories'
    ./test/functional/story_controller_test.rb:65:in `test_should_accept_vote'
    There is an error in the fixtures file stories.yml The records (fixtures) in the file have to have the the same names as the as the test

    Code:
    def test_should_accept_vote
        assert stories(:another).votes.empty?
        post_with_user :vote, :id => 2
        assert ! assigns(:story).reload.votes.empty?
      end
    I can't see your stories.yml, but that is the place to check for that error.

    NOW,
    I am having problems in the same test, but with these functions:

    Code:
     protected
     def get_with_user(action, parameters = nil, session = nil, flash = nil)
        get action, parameters, :user_id => users(:patrick).id
      end
      
      def post_with_user(action, parameters = nil, session = nil, flash = nil)
        post action, parameters, :user_id => users(:patrick).id
      end
    These are returning a nil object.

    Any answers here
    ---------------------------
    Conrad Parvin
    Web Development: http://www.parvin-associates.com
    Web Hosting: http://www.integrityhosting.biz

  10. #10
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    I myself am having the same problem with the protected tests coming back as nil.
    I managed to sort out the one's you commented on. But at present have given myself time away from the shovell app as I was bashing my head against too many trees and not being able to see the wood, of what was going on

  11. #11
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_gis View Post
    Hi there,

    I myself am having the same problem with the protected tests coming back as nil.
    What a difference a day makes! I came back the next day and the post_with_user/get_with_user tests worked. The only thing I can think of is that closing down everything and restarting got it going.
    ---------------------------
    Conrad Parvin
    Web Development: http://www.parvin-associates.com
    Web Hosting: http://www.integrityhosting.biz


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
  •