Passing a paramter/object to a ruby unit/test before running it using TestRunner

Posted by Nahir Khan on Stack Overflow See other posts from Stack Overflow or by Nahir Khan
Published on 2008-11-12T20:49:07Z Indexed on 2010/05/26 3:11 UTC
Read the original article Hit count: 222

Filed under:
|
|

I'm building a tool that automates a process then runs some tests on it's own results then goes to do some other stuff.

In trying to clean up my code I have created a separate file that just has the test cases class. Now before I can run these tests, I have to pass the class a couple of parameters/objects before they can be run. Now the problem is that I can't seem to find a way to pass a parameter/object to the test class.

Right now I am thinking to generate a Yaml file and read it in the test class but it feels "wrong" to use a temporary file for this. If anyone has a nicer solution that would be great!

*********Edit*******

Example Code of what I am doing right now:

#!/usr/bin/ruby
require 'test/unit/ui/console/testrunner'
require 'yaml'
require 'TS_SampleTestSuite'

automatingSomething()
importantInfo = getImportantInfo()

File.open('filename.yml', 'w') do |f|
    f.puts importantInfo.to_yaml
end

Test::Unit::UI::Console::TestRunner.run(TS_SampleTestSuite)

Now in the example above TS_SampleTestSuite needs importantInfo, so the first "test case" is a method that just reads in the information from the Yaml file filname.yml.

I hope that clears up some confusion.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about unit-testing