簡體   English   中英

在上下文之后運行 Rspec 測試中的塊之前

[英]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塊尚未運行測試。 它只是定義它。

itspecify塊,運行時正在執行測試。 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM