A: 

Through the constructor? What am I missing?

CodingWithoutComments
Through the constructor would be the preferred way.
Nahir Khan
A: 

Overall, it looks like you're not really using the unit tests in a very rubyish way, but I'll leave that aside for a minute.

Your basic problem is that you have some setup that needs to happen before the tests run. The normal way to do that is with a setup method within the test unit case itself.

class UserTest < TestUnit::TestCase

  def setup
    # do your important calculation
  end

  def test_success
    #.. assert some things
  end
end

I would give some thought to what code it is that you're actually testing here, and see if you can break it down and test it in a more granular way, with lots more tests.

Cameron Price
From my understanding the method 'setup' runs before each test. I have a setup method already, but I have to have things done before I can run the actual test suite at all. I realize that this isn't the conventional thing to do, but the actual testing is a small part of the whole thing.
Nahir Khan
A: 

First, I agree with Cameron, this code definitely does not adhere to the Ruby way, though I'll also sidestep that for now.

The fastest way to get up and running with this, especially if this data is pretty much immutable (that is to say, your tests won't be altering it in anyway), is to just assign the value to a constant. So instead of naming your variable importantInfo, you name it IMPORTANT_INFO. Then it will be available to you in your tests. It's definitely not a pretty solution, and I think it couuld even be considered a test smell that you need that sort of global setup, but it's there for you.

Alternatively, you could look at stubbing out the importantInfo, which I actually think would provide for much cleaner and more readable tests.

nakajima
Ruby constants are not immutable.irb(main):001:0> IMPORTANT_INFO = "foo"=> "foo"irb(main):002:0> IMPORTANT_INFO = "bar"(irb):2: warning: already initialized constant IMPORTANT_INFO=> "bar"irb(main):003:0> p IMPORTANT_INFO "bar"=> nil
mcl
A: 

hey i m facing the same kinda problem I wana instantiate a test class with my data...i dont knw if thr is any other way other than yaml