[英]Before block in Rspec test run after the context
我正在將一個應用程序從 rails 4 遷移到 rails 6,但現在測試失敗了。 我不太擅長測試,我必須改進,但我不明白為什么在測試之后運行 before 塊。
require 'rails_helper'
RSpec.describe Admin::TrainingEmailsController, type: :controller do
describe "GET #create", :uses_mail do
context "with valid attributes" do
before(:each) do
binding.pry
end
describe "sends the value letter request email" do
binding.pry
it { expect(1+1).to eq(2) }
end
end
end
end
我添加了幾個 pry,當我運行 rspec 時“ sends the value letter request email
”在 before 塊之前運行,所以我的ActionMailer::Base.deliveries.last
是空的
我嘗試使用before
, before(:all)
和before(:each)
它沒有。
describe
塊尚未運行測試。 它只是定義它。
僅it
或specify
塊,運行時正在執行測試。 將binging.pry
放在it
塊中以查看它:
describe "sends the value letter request email" do
binding.pry
let(:mail) { ActionMailer::Base.deliveries.last }
let(:request_sender) { "ValueLetters@vl.balancedview.org" }
let(:accepted_participants_emails) do
training.participants.accepted.
map(&:email)
end
it do
binding.pry # <-- here
expect(mail.to).to match(accepted_participants_emails) }
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.