Closed
Description
Subject of the issue
I'm trying to use the new have_enqueued_email
matcher in one of my specs, but RSpec keeps telling me the format is incorrect
Your environment
- Ruby version: 2.6.5
- rspec-expectations version: 3.9.0
Steps to reproduce
- Write code to schedule a Mailer with
.deliver_now
- Setup RSpec to support ActiveJob
- write the following spec :
expect { post(:email_quote, params: quote_params) }.to have_enqueued_email(MyMailer, :quote)
Expected behavior
Test to pass
Actual behavior
Test fails with the error :
You must pass an argument rather than a block to `expect` to use the provided matcher (have enqueued email QuoteMailer, :quote), or the matcher must implement `supports_block_expectations?`.
The test:
describe "#quote_email" do
subject(:quote_email) { post(:email_quote, params: quote_params) }
let(:email) { "test@example.com" }
let(:quote_params) { { item: item_params, email: email } }
let(:item_params) do
{ variant_id: variant.id, quantity: 100, decoration_id: decoration.id, number_of_colors: 1, is_sample: false }
end
before { ActiveJob::Base.queue_adapter = :test }
it "properly schedules the Mailer for sending the email" do
expect { subject }.to have_enqueued_email(QuoteMailer, :quote)
end
end
The code for invoking in the controller:
def email_quote
item = params.require(:item).permit!.to_h
email = params.require(:email)
QuoteMailer.quote(item, email).deliver_later
render json: true
end
Metadata
Metadata
Assignees
Labels
No labels