Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily override config in Rails test

I need to test some Rails code, but for the duration of my test I would like to override some configuration options.

With Python background, I would do this like:

def test():
    # ...
    with change_config(key, new_value):
       # do stuff with config changed
    # config is back to old value

How would I achieve this in Rails/Ruby?

like image 390
linkyndy Avatar asked Dec 07 '25 22:12

linkyndy


1 Answers

Does this work?

def test
  Rails.config.action_mailer.delivery_method = :test
end
like image 168
Chap Avatar answered Dec 09 '25 10:12

Chap