I taught that, with an option like delivery_method = :test in my config/environments/test.rb I should not receive any mails while running my Rspec tests:
config/environments/test.rb:
config.action_mailer.delivery_method = :test
But in my tests, when I create a user with FactoryGirl and the user has an after_save callback that sends a signup-notification, this email will be sent:
myspec.rb:
user = FactoryGirl.create(:user, :login => 'johndoe')
user_observer.rb:
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.signup_notification(user).deliver
end
end
action_mailer.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "...",
:port => "25",
:domain => "...",
:user_name => "...",
:password => "...",
:authentication => :plain
}
What can be wrong?
I’m using:
- Rails 3.2.2
- buildin ActionMailer
- RSpec-Rails
- FactoryGirl
- Guard
Yes, you are right. ActionMailer::Base.delivery_method = :smtp masks your configuration in environment/test.rb
I propose you next solution: create fixture with specific data for each scope.
like in enter link description here
in my case it looks like:
my config.yml
my environment.rb