问题
I have recently upgraded a project to Rails 5.1.
- All deprecation warnings were fixed.
- All tests pass (I use
rspec-rails
) - Controller tests that call mailers using ActiveJob are now rendering lengthy warning messages.
[ActiveJob] [ActionMailer::DeliveryJob] [6d2ec032-eff2-40d3-bad4-3b23de65d9bd] Could not log "render_template.action_view" event. NoMethodError: undefined method 'example_group' for nil:NilClass [
"rails/view_rendering.rb:67:in 'current_example_group'", "rspec/rails/view_rendering.rb:71:in 'render_template'", "active_support/subscriber.rb:99:in 'finish'",
... LIST SHORTENED FOR CLARITY ...
"active_job/execution.rb:20:in 'execute'",
... LIST SHORTENED ...
"concurrent/executor/ruby_thread_pool_executor.rb:319:in 'block in create_worker'" ]
What has changed in Rails 5.1 for testing (API) controllers that send emails? Am I doing something wrong?
describe Api::UsersController do
it 'creates a new user' do
# THIS ENDPOINT CALLS
# UserMailer.welcome_email(user).deliver_later
post :create, params: params
end
end
回答1:
I had the same problem and was using rspec-rails 3.6.0
. I've downgraded back to 3.5.0
which fixed the issue for me.
来源:https://stackoverflow.com/questions/43983466/controller-test-emits-debug-failure-messages-after-rails-5-1-upgrade