Help with test configuration

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

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

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



class Something

override constant

CONSTANT = “something else”

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

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

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



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

Hope this helps.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs