Why does bebeug / pry stop at a breakpoint in Rspec ActionMailer?

I am trying to debug my user_mailer.rb in my test environment. But I don’t know why the debugger does not stop where it was supposed.

So, the code that I roughly have: 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

 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 beebug / pry does not stop in user_mail.rb when I run the rspec spec/mailer/user_mailer_spec.rb ?

And why?

How to make him stop at this breakpoint?

Is there a bug in the debugger?

+7
ruby-on-rails rspec pry actionmailer byebug
source share
2 answers

UserMailer.send_notification_letters(user) does not actually call the send_notification action, but instead returns an ActionMailer::MessageDelivery object. You must call delivery to get into the method, for example:

UserMailer.send_notification_letters(user).deliver_now

You can read more about the topic at http://api.rubyonrails.org/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Sending+mail

+2
source share

Today I faced the same situation. After digging, I found that my problem was caused by the thin server daemonize .

Change your config/thin.yml :

 daemonize: false 

Or you can just comment on the thin stone in your Gemfile, use WEBrick by default instead.

0
source share

All Articles