Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Rake TestTask screwing with global variables?

Reply
Thread Tools

Rake TestTask screwing with global variables?

 
 
Drew Olson
Guest
Posts: n/a
 
      03-10-2008
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-forum.com/.

 
Reply With Quote
 
 
 
 
Stefan Lang
Guest
Posts: n/a
 
      03-10-2008
2008/3/10, Drew Olson <>:
> 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

 
Reply With Quote
 
 
 
 
Drew Olson
Guest
Posts: n/a
 
      03-10-2008
Stefan Lang wrote:
> 2008/3/10, Drew Olson <>:
>> 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-forum.com/.

 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      03-11-2008
2008/3/10, Drew Olson <>:
> Stefan Lang wrote:
> > 2008/3/10, Drew Olson <>:
> >> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Problem : Including gems in Rake::TestTask Michael Barton Ruby 0 02-14-2008 05:36 PM
Rake TestTask running its block anytime rake is invoked Adam Anderson Ruby 1 09-19-2007 08:40 AM
Properly using Rake::TestTask gga Ruby 0 03-21-2007 08:13 PM
Rake and rake aborted! Rake aborted! undefined method `gem' for main:Object peppermonkey Ruby 1 02-10-2007 04:43 AM
Rake 0.7.0 breaks "rake engine_migrate"? Joe Van Dyk Ruby 2 01-31-2006 12:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57