Help with test configuration


#1

Thanks in advance for reading this, double thanks for a response, triple
for something that works.

I need a way to separate some environment variables for my development
rails app and for testing my rails app. I have a few environment.rb
constants set, but when I put them into the config/environment/test.rb
file as constants to override the environment.rb constants, i get an
error that says the constants have already been setup. I know I can’t
set constants twice, I thought the test.rb overwrote the shared
environment.rb file, I guess I am wrong.

Does anyone know how to do this another way? Perhaps using something
other than constants? I have tried a few things blind, but they don’t
work. Suggestions?

-Jon Dodson
Open Source Software Engineer
Open Sourcery LLC
http://www.opensourcery.com


#2

work. Suggestions?
I ran into the same problem last night. This is what I came up with.

something.rb:
class Something
CONSTANT = “something” unless defined?( CONSTANT ).nil?

end

environment.rb:

class Something

override constant

CONSTANT = “something else”
end

Class variables look like the other way to do it (esp. if you add a
“config” class method to set them). However, I was working with
mixins and was getting indeterminate results accessing the class
variable both from within the module and from within overridden
methods.

This approach would look something like this:
something.rb:
class Something
@@variable = “default value”

def self.config(options = {})
options = { :variable => @@variable }.update( options ) if
options.is_a?(Hash)
@@variable = options[:variable]
end

end

environment.rb:

Something.config( :variable => “overridden value” )

Hope this helps.
seth