[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rake TestTask screwing with global variables?

Drew Olson

3/10/2008 9:42:00 PM

I've got a rake TestTask that I have set a global variable in specific
cases (I know, I know, tsk tsk). However, this value doesn't seem to be
available to my tests. This seems very strange to me. The variable
should be global, right? Below is a simple example. The test case fails
as the value of $test is nil and I have no idea why.

My rakefile.rb is:

require 'rake/testtask'

Rake::TestTask.new do |t|
$test = "this is a test"
t.test_files = FileList["my_test.rb"]
end

My test case my_test.rb is:

require 'test/unit'

class MyTest < Test::Unit::TestCase
def test_global_variable
assert_equal "this is a test", $test
end
end

Any idea why this doesn't work?

Thanks,
Drew
--
Posted via http://www.ruby-....

3 Answers

Stefan Lang

3/10/2008 9:54:00 PM

0

2008/3/10, Drew Olson <olsonas@gmail.com>:
> I've got a rake TestTask that I have set a global variable in specific
> cases (I know, I know, tsk tsk). However, this value doesn't seem to be
> available to my tests. ...

The tests are run in new ruby processes, not in the
rake process itself.

Stefan

Drew Olson

3/10/2008 10:09:00 PM

0

Stefan Lang wrote:
> 2008/3/10, Drew Olson <olsonas@gmail.com>:
>> I've got a rake TestTask that I have set a global variable in specific
>> cases (I know, I know, tsk tsk). However, this value doesn't seem to be
>> available to my tests. ...
>
> The tests are run in new ruby processes, not in the
> rake process itself.
>
> Stefan

Ugh, I had suspicions this was the case. How does one pass information
(for example, which config file to use) that is given to the rake task
at the command line to the test case itself?

- Drew
--
Posted via http://www.ruby-....

Stefan Lang

3/11/2008 1:45:00 AM

0

2008/3/10, Drew Olson <olsonas@gmail.com>:
> Stefan Lang wrote:
> > 2008/3/10, Drew Olson <olsonas@gmail.com>:
> >> I've got a rake TestTask that I have set a global variable in specific
> >> cases (I know, I know, tsk tsk). However, this value doesn't seem to be
> >> available to my tests. ...
> >
> > The tests are run in new ruby processes, not in the
> > rake process itself.
> >
> > Stefan
>
>
> Ugh, I had suspicions this was the case. How does one pass information
> (for example, which config file to use) that is given to the rake task
> at the command line to the test case itself?

Simple parameters can be passed via environment variables.

So put ENV["SOME_VAR"] = foo in the Rakefile and access
it via ENV["SOME_VAR"] in the test process.

You can also set an environment variable on the rake commandline:

$ rake some_task SOME_VAR=foo

Stefan