Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6052457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:55:51+00:00 2026-05-23T07:55:51+00:00

So.. here is the top of my unit test file. class ObjectTest < ActiveSupport::TestCase

  • 0

So.. here is the top of my unit test file.

class ObjectTest < ActiveSupport::TestCase
  @user = -1

the test that fails (also the first one to use @user)

test "for detection of first content" do
  puts "+++++++++++++++++++++++++++++ #{@user.name}"

And this is the error I get

NoMethodError: undefined method `name' for nil:NilClass

Now, I know that a number can’t have any attributes like .name.. but I’m trying to solve a problem unrelated to trying to get the name of integers. The problem is that instance variable defined anywhere in my test file instantly turn to nil when na test begins — as you can, the actual content of the test doesn’t matter, the data inside @user is vanishing somehow. =\

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:55:51+00:00Added an answer on May 23, 2026 at 7:55 am

    Class instance variables are a little odd, and I’ve not used them that much, but if I grok them correctly, they exist on the class itself and can only be accessed with the @ symbol in class methods – so you will have to access @user as ObjectTest.user or self.class.user when you are in instance methods, otherwise Ruby will look for the instance instance variable inside of instance methods. In other words, in a class function, you can refer to @user, but in an instance function, Ruby is looking for the @user variable on the instance. here is a page that seems to demonstrate this behavior.

    Since class variables (e.g. @@user) use a completely different syntax, they should not show this scope-colliding behavior – you can use @@user in both class and instance methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a js file at here , on the very top of this
I'm looking for some advice for unit-testing in a manner that doesn't leave test
I am running a unit test on a user model in ruby. I am
I am testing some Ruby code and have a failing Test::Unit::TestCase. Unfortunately, the failure
Here is my select statement, SELECT TOP 1 EmpId, RemainingAdvance FROM SalaryDetails WHERE EmpId
Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top
Let say here is my stack layout View3 --> Top of the stack View2
To replicate the error go here: http://racedayworld-com.si-eioswww3.com/ And press the button at the top
I am trying to create a reliable service on top of UDP. Here i
It has to be simple, here's my CSS: .progressImage { position:relative; top:50%; } .progressPanel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.