setup method in functional tests and instance variables

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 = user(:invalid_user)   @valid_user = users(:valid_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

The above should work just fine, given that you have a user fixture named 'valid_user'. Do you see something like this in test/fixtures/ users.yaml?

valid_user:   screen_name: xyz

David Knorr wrote:

@valid_user = users(:valid_user) The error occurred while evaluating nil.screen_name

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

Any ideas.

The above should work just fine, given that you have a user fixture named 'valid_user'. Do you see something like this in test/fixtures/ users.yaml?

valid_user:   screen_name: xyz

-- Best regards, David Knorr http://twitter.com/rubyguy

HI David

This is my yaml

valid_user:    id: 1    screen_name: millikan    email: ram@example.com    password: electron

Now here is the weird thing.

if I do the following in the actual test method

def test_login_success @valid_user = users(:valid_user)   @valid_user.screen_name end

it works just fine.

Its like I can't access instance variables that run in the setup. Why would that be?

For my units test I have a similar setup and it works no problem.

What do mean when saying "fix this". Did you run the rails:update rake task?

David Knorr wrote:

ActiveSupport::TestCase

from

ActionController::TestCase

works like a charm.

Why don't they fix this?

What do mean when saying "fix this". Did you run the rails:update rake task?

-- Best regards, David Knorr. http://twitter.com/rubyguy

I did run rails:update rake. And I updated rails. But even now when I run script/generate controller someController I have to edit the test file so that it is changed from ActionController::Testcase to ActiveSupport::TestCase.

Should I update something else so I don't have to do this everytime? And it does this only for the functionals not the unit test skeletons.

Mitch

Did you upgrade to another version of Rails recently?

David Knorr wrote:

Mitchell,

Sounds like you should maybe just bite the bullet and upgrade to 2.3.2 if that's being an issue.

When you say "If I move up to another version [of Rails], my application does not work", what do you mean? Can you provide specific errors?

Best, Milan

Milan Iliev wrote:

Mitchell,

Sounds like you should maybe just bite the bullet and upgrade to 2.3.2 if that's being an issue.

When you say "If I move up to another version [of Rails], my application does not work", what do you mean? Can you provide specific errors?

Best, Milan

On Apr 22, 12:48�am, Mitchell Gould <rails-mailing-l...@andreas-s.net>

Just a quick reply.

Two things:

1. How do I move my app to 2.3.2? Do I just change the configuration settings? 2. When I have done this in the past the application won't start up meaning the server won't launch.

Thanks for your reply

Mitch