Before block in Rspec test 运行 after context
Before block in Rspec test run after the context
我正在将一个应用程序从 rails 4 迁移到 rails 6,现在测试失败了。
我的测试不太好,我必须改进,但我不明白为什么测试后的前块运行。
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
我加了几个撬,当我 运行 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
我正在将一个应用程序从 rails 4 迁移到 rails 6,现在测试失败了。 我的测试不太好,我必须改进,但我不明白为什么测试后的前块运行。
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
我加了几个撬,当我 运行 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