Ruby on rails 为什么byebug/pry不在Rspec ActionMailer中的断点处停止?
我尝试在测试环境中调试用户_mailer.rb。但是我不知道为什么调试器不停在它应该停的地方 因此,我大致掌握的代码是:Ruby on rails 为什么byebug/pry不在Rspec ActionMailer中的断点处停止?,ruby-on-rails,rspec,actionmailer,pry,byebug,Ruby On Rails,Rspec,Actionmailer,Pry,Byebug,我尝试在测试环境中调试用户_mailer.rb。但是我不知道为什么调试器不停在它应该停的地方 因此,我大致掌握的代码是: user\u mailer\u spec.rb describe UserMailer do describe '#send_notification_letters' do # bunch of code omitted here ... it 'should record itself to the database' expect { U
user\u mailer\u 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
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
在user\u mailer.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
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
class UserMailer
问题是,当我运行测试时,为什么byebug/pry没有在user\u-mail.rb
中停止
为什么
如何让它停在那个断点
调试器中有错误吗?我今天遇到了同样的情况。仔细研究后,我发现我的问题是由thin
服务器的daemonize
配置引起的
编辑您的配置/thin.yml
:
daemonize: false
或者,您可以只注释掉gem文件中的thin
gem,改用默认的WEBrick
。UserMailer.send\u notification\u letters(user)
实际上并不调用send\u notification
操作,而是返回一个ActionMailer::MessageDelivery
对象。您需要调用传递以命中该方法,如下所示:
UserMailer.发送通知信(用户)。立即发送
您可以在中阅读有关该主题的更多信息。我遇到了相同的问题,只需重新启动服务器
在我的例子中是puma,没有spring。你在日志中得到了什么?这种情况经常发生在我身上,除非我在byebug
行上方添加require'byebug'
。@MohammadAbuShady,test.log中只有一堆SQL事务日志,这意味着UserMailer。已执行发送通知函()。但是调试器没有停止。日志中没有关于调试器的任何内容。@infused,trustedrequire'byebug'
,在expect工作之前对我添加byebug没有任何帮助?我也有同样的问题,但我相信这不是一个thin
问题,因为我没有使用它。:)彼此彼此。我用的是美洲狮。如果可以的话,我会把它投上一千次;我快发疯了,谢谢!