SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    instance variables and test functionals

    I have the following in my functional test file.

    class UserControllerTest < ActionController::TestCase
    fixtures :users

    def setup
    @controller = UserController.new
    @request = ActionController::TestRequest.new
    @response = ActionController::TestResponse.new
    @invalid_user = userinvalid_user)
    @valid_user = usersvalid_user)
    end

    def test_login_success
    @valid_user.screen_name
    end

    When I run a test that tries to use the @valid_user variable I get the
    following error.

    NoMethodError: You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.screen_name

    It seems that this class isn't storing the instance variables in memory.

    Any ideas.

    Thanks in advance

    Mitch


    I just found the answer. Cryptic little bugger.

    t's worth noting that R2.0.2 subclasses ActionController::TestCase
    for functional tests (i.e. UserControllerTest), not
    ActiveSupport::TestCase. You need to explicitly change the skeleton
    test files for (user|spec|etc)_controller_test.rb files to subclass
    ActiveSupport::TestCase.
    Last edited by mitchai; Apr 6, 2009 at 08:14. Reason: found the answer

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,161
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Thanks for posting your solution. I haven't upgraded from 1.8 yet, and I've yet to write any code that uses instance variables, but I'm wondering how/where you found the helpful information.

  3. #3
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    Thanks for posting your solution. I haven't upgraded from 1.8 yet, and I've yet to write any code that uses instance variables, but I'm wondering how/where you found the helpful information.
    I found it by looking at the website for the books website RailsSpace.com/book I think.

    There they have some updates etc and a listing for the google group for RailsSpace.

    On that site I found someone else who had the same problem and posted the solution. I hope this helps.


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
  •