I'm using Rails 5.1.6 and Ruby 2.5.1 (though had the same error on previous builds).
我正在使用Rails 5.1.6和Ruby 2.5.1(虽然在以前的版本中有相同的错误)。
Switching over a mailer from deliver_now to deliver_later. Works fine in my browser, however I'm stuck trying to get my integration tests working. Seemingly using any methods from ActiveJob::TestHelper triggers the following error:
将邮件从deliver_now切换到deliver_later。在我的浏览器中正常工作,但是我试图让我的集成测试工作。看似使用ActiveJob :: TestHelper中的任何方法会触发以下错误:
Error: SendJobToContactsTest#test_send_job_to_contacts: SystemStackError: stack level too deep
错误:SendJobToContactsTest#test_send_job_to_contacts:SystemStackError:堆栈级别太深
Integration Test Code:
集成测试代码:
require 'test_helper'
include ActiveJob::TestHelper
class SendJobToContactsTest < ActionDispatch::IntegrationTest
...
end
This works fine:
这很好用:
assert_difference 'ContactJob.count', 1 do
patch update_contacts_user_job_path(@user, @job), params: {job: {contact_ids: [ @contact2.id], message: {message_text: "This is a test"}}}
end
Using performed_enqueued_jobs
triggers the SystemStackError:
使用done_enqueued_jobs会触发SystemStackError:
assert_difference 'ContactJob.count', 1 do
perform_enqueued_jobs do
patch update_contacts_user_job_path(@user, @job), params: {job: {contact_ids: [ @contact2.id], message: {message_text: "This is a test"}}}
end
end
Even just assert_enqueued_jobs
without performed_enqueued_jobs
triggers the SystemStackError:
即使只是assert_enqueued_jobs而没有done_enqueued_jobs也会触发SystemStackError:
assert_difference 'ContactJob.count', 1 do
patch update_contacts_user_job_path(@user, @job), params: {job: {contact_ids: [ @contact2.id], message: {message_text: "This is a test"}}}
assert_enqueued_jobs 1
end
And turns out even just calling an empty perform_enqueued_jobs block (with none of my code involved) triggers the stack level too deep issue:
事实证明,即使只调用一个空的perform_enqueued_jobs块(不涉及我的代码)也会触发堆栈级别太深的问题:
perform_enqueued_jobs do
# do something later
end
1 个解决方案
#1
1
Turns out the issue was where I had the include statement. Moving it within the class solved the issue:
原来问题是我有include语句的地方。在课堂上移动它解决了这个问题:
require 'test_helper'
class SendJobToContactsTest < ActionDispatch::IntegrationTest
include ActiveJob::TestHelper
#1
1
Turns out the issue was where I had the include statement. Moving it within the class solved the issue:
原来问题是我有include语句的地方。在课堂上移动它解决了这个问题:
require 'test_helper'
class SendJobToContactsTest < ActionDispatch::IntegrationTest
include ActiveJob::TestHelper