I have a question about integration testing. When I run “rake test” I get no errors.
But when I run “rake test:integration” I get:
1) Error: UserStoriesTest#test_buying_a_product: NoMethodError: undefined method `to' for nil:NilClass test/integration/user_stories_test.rb:50:in `block in <class:UserStoriesTest>' 1 tests, 17 assertions, 0 failures, 1 errors, 0 skips
In the log file “test.log” I can see that an email has been sent and I also get an actual emai from the test.
In my config/environments/test.rb file the delivery method for Action Mailer is set to “:test”:
# Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test
So why do I get an email when I run “rake test:integration”? And why is ActionMailer::Base.deliveries empty after this?
The integration test fails because mail is nil:
mail = ActionMailer::Base.deliveries.last assert_equal ["firstname.lastname@example.org"], mail.to