[英]Why doesnt byebug/pry stop at the breakpoint in Rspec ActionMailer?
I try to debug my user_mailer.rb within my test environment.我尝试在我的测试环境中调试我的 user_mailer.rb。 But I dont know why the debugger doesnst stop where it suppose to.
但我不知道为什么调试器不会在它应该停止的地方停止。
So, the code I roughly have is: user_mailer_spec.rb
所以,我大致拥有的代码是:
user_mailer_spec.rb
describe UserMailer do
describe '#send_notification_letters' do
# bunch of code omitted here ...
it 'should record itself to the database'
expect { UserMailer.send_notification_letters(user) }.to change{SentMail.count}.by(1)
end
end
end
In user_mailer.rb
在
user_mailer.rb
class UserMailer < ActionMailer::Base
def send_notification_letters(user)
byebug # should break here but doesnt,
# also tried binding.pry here, also doesnt work
# buggy code ...
# buggy code ...
# buggy code ...
SentMail.create(...) # never reached
mail(to:..., from:...)
end
end
The question is, why is byebug/pry not stopping in the user_mail.rb
when i run the test rspec spec/mailer/user_mailer_spec.rb
?现在的问题是,为什么是byebug /撬在不停止
user_mail.rb
当我运行测试rspec spec/mailer/user_mailer_spec.rb
?
And why?为什么?
How to make it stop at that break point?如何让它在那个断点处停止?
Is there a bug in the debugger?调试器中是否有错误?
UserMailer.send_notification_letters(user)
does not actually call the the send_notification
action, but instead it returns an ActionMailer::MessageDelivery
object. UserMailer.send_notification_letters(user)
实际上并没有调用send_notification
操作,而是返回一个ActionMailer::MessageDelivery
对象。 You need to invoke the delivery in order to hit the method, like this:您需要调用交付才能命中该方法,如下所示:
UserMailer.send_notification_letters(user).deliver_now
You can read more on the topic in http://api.rubyonrails.org/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Sending+mail您可以在http://api.rubyonrails.org/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Sending+mail 中阅读有关该主题的更多信息
I've run into the same situation today.我今天遇到了同样的情况。 After digging around, I've found my issue is caused by the
thin
server's daemonize
configuration.在挖掘之后,我发现我的问题是由
thin
服务器的daemonize
配置引起的。
Edit your config/thin.yml
:编辑您的
config/thin.yml
:
daemonize: false
Or you can just comment out the thin
gem in your Gemfile, use the default WEBrick
instead.或者你可以在你的 Gemfile 中注释掉
thin
gem,使用默认的WEBrick
代替。
I had the same problem, just restart the server.我有同样的问题,只需重新启动服务器。
In my case puma, and without spring.就我而言,puma 没有弹簧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.