为什么byebug/pry在Rspec ActionMailer的断点处停止?

Sid*_*hou 10 rspec ruby-on-rails actionmailer pry byebug

我尝试在我的测试环境中调试我的user_mailer.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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

问题是,为什么byebug/pry user_mail.rb在我进行测试时没有停止rspec spec/mailer/user_mailer_spec.rb

为什么?

如何让它在那个断点停下来?

调试器中是否有错误?

ify*_*ndy 1

我今天也遇到了同样的情况。经过一番研究,我发现我的问题是由thin服务器daemonize配置引起的。

编辑您的config/thin.yml

daemonize: false
Run Code Online (Sandbox Code Playgroud)

thin或者您可以在 Gemfile 中注释掉gem,使用默认值WEBrick