Module: RSpec::Rails::Matchers
Overview
Container module for ::RSpec::Rails
specific matchers.
Class Method Summary
::RSpec::Matchers::DSL
- Extended
alias_matcher | Defines a matcher alias. |
define | Defines a custom matcher. |
define_negated_matcher | Defines a negated matcher. |
matcher | Alias for Matchers::DSL#define. |
warn_about_block_args | :nocov: |
Instance Method Summary
-
#be_a_new(model_class)
Passes if actual is an instance of
model_class
and returnstrue
fornew_record?
. -
#be_new_record
Passes if actual returns
true
fornew_record?
. -
#be_valid(*args)
Passes if the given model instance’s
valid?
method is true, meaning all of theActiveModel::Validations
passed and no errors exist. -
#enqueue_email(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
-
#enqueue_job(job = nil)
Alias for #have_enqueued_job.
-
#enqueue_mail(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
-
#have_been_enqueued
Passes if a job has been enqueued.
-
#have_been_performed
Passes if a job has been performed.
-
#have_broadcasted_to(target = nil)
Passes if a message has been sent to a stream/object inside a block.
-
#have_enqueued_email(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
-
#have_enqueued_job(job = nil)
(also: #enqueue_job)
Passes if a job has been enqueued inside block.
-
#have_enqueued_mail(mailer_class = nil, mail_method_name = nil)
(also: #have_enqueued_email, #enqueue_mail, #enqueue_email)
Passes if an email has been enqueued inside block.
-
#have_http_status(target)
Passes if
response
has a matching HTTP status code. -
#have_performed_job(job = nil)
(also: #perform_job)
Passes if a job has been performed inside block.
-
#perform_job(job = nil)
Alias for #have_performed_job.
-
#receive_inbound_email(message)
Passes if the given inbound email would be routed to the subject inbox.
-
#send_email(criteria = {})
Check email sending with specific parameters.
- #check_action_cable_adapter private Internal use only Internal use only
- #check_active_job_adapter private Internal use only Internal use only
Instance Method Details
#be_a_new(model_class)
Passes if actual is an instance of model_class
and returns true
for new_record?
. Typically used to specify instance variables assigned to views by controller actions
Use the with
method to specify the specific attributes to match on the new record.
#be_new_record
Passes if actual returns true
for new_record?
.
# File 'rspec-rails/lib/rspec/rails/matchers/be_new_record.rb', line 25
def be_new_record BeANewRecord.new end
#be_valid(*args)
Passes if the given model instance’s valid?
method is true, meaning all of the ActiveModel::Validations
passed and no errors exist. If a message is not given, a default message is shown listing each error.
#check_action_cable_adapter (private)
# File 'rspec-rails/lib/rspec/rails/matchers/action_cable.rb', line 63
def check_action_cable_adapter return if ::ActionCable::SubscriptionAdapter::Test === ::ActionCable.server.pubsub raise StandardError, "To use ActionCable matchers set `adapter: test` in your cable.yml" end
#check_active_job_adapter (private)
#enqueue_email(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
# File 'rspec-rails/lib/rspec/rails/matchers/have_enqueued_mail.rb', line 255
alias_method :enqueue_email, :have_enqueued_mail
#enqueue_job(job = nil)
Alias for #have_enqueued_job.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 405
alias_method :enqueue_job, :have_enqueued_job
#enqueue_mail(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
# File 'rspec-rails/lib/rspec/rails/matchers/have_enqueued_mail.rb', line 254
alias_method :enqueue_mail, :have_enqueued_mail
#have_been_enqueued
Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 436
def have_been_enqueued check_active_job_adapter ActiveJob::HaveBeenEnqueued.new end
#have_been_performed
Passes if a job has been performed. May chain at_least, at_most or exactly to specify a number of times.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 509
def have_been_performed check_active_job_adapter ActiveJob::HaveBeenPerformed.new end
#have_broadcasted_to(target = nil)
Passes if a message has been sent to a stream/object inside a block. May chain at_least
, at_most
or exactly
to specify a number of times. To specify channel from which message has been broadcasted to object use from_channel
.
# File 'rspec-rails/lib/rspec/rails/matchers/action_cable.rb', line 50
def have_broadcasted_to(target = nil) check_action_cable_adapter ActionCable::HaveBroadcastedTo.new(target, channel: described_class) end
#have_enqueued_email(mailer_class = nil, mail_method_name = nil)
Alias for #have_enqueued_mail.
# File 'rspec-rails/lib/rspec/rails/matchers/have_enqueued_mail.rb', line 253
alias_method :have_enqueued_email, :have_enqueued_mail
#have_enqueued_job(job = nil) Also known as: #enqueue_job
Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 401
def have_enqueued_job(job = nil) check_active_job_adapter ActiveJob::HaveEnqueuedJob.new(job) end
#have_enqueued_mail(mailer_class = nil, mail_method_name = nil) Also known as: #have_enqueued_email, #enqueue_mail, #enqueue_email
Passes if an email has been enqueued inside block. May chain with to specify expected arguments. May chain at_least, at_most or exactly to specify a number of times. May chain at to specify a send time. May chain on_queue to specify a queue.
# File 'rspec-rails/lib/rspec/rails/matchers/have_enqueued_mail.rb', line 250
def have_enqueued_mail(mailer_class = nil, mail_method_name = nil) HaveEnqueuedMail.new(mailer_class, mail_method_name) end
#have_http_status(target)
Passes if response
has a matching HTTP status code.
The following symbolic status codes are allowed:
-
Rack::Utils::SYMBOL_TO_STATUS_CODE
-
One of the defined
ActionDispatch::TestResponse
aliases:-
:error
-
:missing
-
:redirect
-
:success
-
# File 'rspec-rails/lib/rspec/rails/matchers/have_http_status.rb', line 374
def have_http_status(target) raise ArgumentError, "Invalid HTTP status: nil" unless target HaveHttpStatus.matcher_for_status(target) end
#have_performed_job(job = nil) Also known as: #perform_job
Passes if a job has been performed inside block. May chain at_least, at_most or exactly to specify a number of times.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 476
def have_performed_job(job = nil) check_active_job_adapter ActiveJob::HavePerformedJob.new(job) end
#perform_job(job = nil)
Alias for #have_performed_job.
# File 'rspec-rails/lib/rspec/rails/matchers/active_job.rb', line 480
alias_method :perform_job, :have_performed_job
#receive_inbound_email(message)
Passes if the given inbound email would be routed to the subject inbox.
# File 'rspec-rails/lib/rspec/rails/matchers/action_mailbox.rb', line 68
def receive_inbound_email( ) ActionMailbox::ReceiveInboundEmail.new( ) end
#send_email(criteria = {})
Check email sending with specific parameters.