PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Rake TestTask screwing with global variables?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Rake TestTask screwing with global variables?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/03/2008, 22h41   #1
Drew Olson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Rake TestTask screwing with global variables?

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/.

  Réponse avec citation
Vieux 10/03/2008, 22h53   #2
Stefan Lang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Rake TestTask screwing with global variables?

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

  Réponse avec citation
Vieux 10/03/2008, 23h08   #3
Drew Olson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Rake TestTask screwing with global variables?

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-forum.com/.

  Réponse avec citation
Vieux 11/03/2008, 02h45   #4
Stefan Lang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Rake TestTask screwing with global variables?

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11477 seconds with 12 queries