views:

30

answers:

1

Hey,

Im using rspec and when i run rake spec, the user mailer sends email through smtp and not stores the email in the ActionMailer::Base.deliveries-array (invoked by an user-observer)...

Could you give me a hint why?

# Rails version
rails -v
=> Rails 3.0.1

# Ruby version with rvm (rvm version 1.0.16)
ruby -v
=> ruby 1.9.2p7 (2010-09-29 revision 29373) [x86_64-darwin10.4.0]

# Gemfile
gem "rspec-rails", ">= 2.0.1"

Config-files:

# config/environments/test.rb
MyApp::Application.configure do
  config.action_mailer.delivery_method = :test
  config.action_mailer.raise_delivery_errors = true
end

# spec/spec_helper.rb
...
ENV["RAILS_ENV"] ||= 'test'
...

# app/models/user_observer.rb
class UserObserver < ActiveRecord::Observer
  observe User

  def after_create(record)
    puts Rails.env
    # => "test"
    UserMailer.new_user_notification(record).deliver
    puts ActionMailer::Base.deliveries.inspect
    # => []
    # Sends it via smtp!
  end
end
A: 

I'm so dumb... had "ActionMailer::Base.delivery_method = :smtp" in my setup_mail.rb-initializer... AAARGH....

Lichtamberg