[LRUG] Defining constants in ActiveSupport::TestCase ?

James Adam james at lazyatom.com
Fri Aug 21 09:04:39 PDT 2009


I'm surprised you're seeing this, given that functional and unit tests
run in seperate ruby processes using the default Rails rake tasks. You
should be able to verify this is true by looking at the rake output:

$ rake
(in /Users/james/Code/project)
/opt/local/bin/ruby -I"/Users/james/Code/project/lib"
-I"/Users/james/Code/project/test"
"/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb"
"test/unit/my_model.rb" (and then a bunch more files...)
/opt/local/bin/ruby -I"/Users/james/Code/project/lib"
-I"/Users/james/Code/project/test"
"/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb"
"test/functional/my_controller.rb" (and then a bunch more files...)

As you can see, the unit and functional tests are actually being
invoked using independent ruby instances. Does that help you track
anything down, or at least eliminate one possible source of conflicts?

- James

2009/8/21 Taryn East <teast at globalpersonals.co.uk>:
> So - we have a few constants we use in testing. They're used for both
> functional and integration tests (and some of the unit tests too), so we've
> pulled them into ActiveSupport::TestCase in a test helper file.
>
> This works fine when you run, say, just "rake test:X" (where X is
> units/functionals etc), but when you run just "rake test" it complains that
> I've defined them twice.
>
> We've since added an "if defined?(CONST_NAME)" to the end of each one -
> which cuts the warnings nicely... but I was thinking that surely there's a
> way to make sure that it's all only loaded once.
>
> Does anybody know?
>
> thanks in advance,
> Taryn
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>



More information about the Chat mailing list