我试图通过devise
测试rspec
邮件。
这是 devise_mailer_spec.rb
要求" rails_helper"
RSpec.describe Devise::Mailer do
it "sends a confirmation email to correct email with custom text" do
user = FactoryGirl.create(:user, confirmed_at: nil)
confirmation_email = Devise.mailer.deliveries.last
expect(user.email).to eq confirmation_email.to[0]
expect(confirmation_email.body.to_s).to have_content 'You can confirm your account email'
end
end
但是,我收到了这个错误。
Failures:
1) Devise::Mailer sends a confirmation email to correct email with custom text
Failure/Error: expect(confirmation_email.body.to_s).to have_content 'You can confirm your account email'
expected <p>Welcome adolfo@schoen.io!</p>
<p>You can confirm your account email through the link below:</p>
<p><a href="http://localhost:3000/users/confirmation?confirmation_token=sPMPQRe5SLDPgpakVy3J">Confirm my account</a></p>
to respond to `has_content?`
# ./spec/mailers/devise_mailer_spec.rb:9:in `block (2 levels) in <top (required)>'
Finished in 8 minutes 38 seconds (files took 5.02 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/mailers/devise_mailer_spec.rb:4 # Devise::Mailer sends a confirmation email to correct email with custom text
我已将binding.pry
设置为代码,我可以确保confirmation_email.body.to_s
将抛出
"<p>Welcome edgardo@heidenreich.name!</p>\n\n<p>You can confirm your account email through the link below:</p>\n\n<p><a href=\"http://localhost:3000/users/confirmation?confirmation_token=_qi3a9rsucm6YhG8CUjt\">Confirm my account</a></p>\n"
答案 0 :(得分:0)
尝试:
expect(confirmation_email.body.encoded).to include 'You can confirm your account email'