Module: RSpec::Rails::Matchers
- Defined in:
- lib/rspec/rails/matchers.rb,
lib/rspec/rails/matchers/be_a_new.rb,
lib/rspec/rails/matchers/be_valid.rb,
lib/rspec/rails/matchers/active_job.rb,
lib/rspec/rails/matchers/send_email.rb,
lib/rspec/rails/matchers/redirect_to.rb,
lib/rspec/rails/matchers/action_cable.rb,
lib/rspec/rails/matchers/base_matcher.rb,
lib/rspec/rails/matchers/be_new_record.rb,
lib/rspec/rails/matchers/have_rendered.rb,
lib/rspec/rails/matchers/action_mailbox.rb,
lib/rspec/rails/matchers/have_http_status.rb,
lib/rspec/rails/matchers/routing_matchers.rb,
lib/rspec/rails/matchers/have_enqueued_mail.rb,
lib/rspec/rails/matchers/action_cable/have_streams.rb,
lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb
Overview
Container module for Rails specific matchers.
Defined Under Namespace
Modules: ActionCable, ActionMailbox, ActiveJob, HaveHttpStatus, RedirectTo, RenderTemplate, RoutingMatchers Classes: BaseMatcher, BeANew, SendEmail
Instance Method Summary collapse
-
#be_a_new(model_class) ⇒ Object
Passes if actual is an instance of
model_class
and returnstrue
fornew_record?
. -
#be_new_record ⇒ Object
Passes if actual returns
true
fornew_record?
. -
#be_valid(*args) ⇒ Object
Passes if the given model instance's
valid?
method is true, meaning all of theActiveModel::Validations
passed and no errors exist. -
#have_been_enqueued ⇒ Object
Passes if a job has been enqueued.
-
#have_been_performed ⇒ Object
Passes if a job has been performed.
-
#have_broadcasted_to(target = nil) ⇒ Object
(also: #broadcast_to)
Passes if a message has been sent to a stream/object inside a block.
-
#have_enqueued_job(job = nil) ⇒ Object
(also: #enqueue_job)
Passes if a job has been enqueued inside block.
-
#have_enqueued_mail(mailer_class = nil, mail_method_name = nil) ⇒ Object
(also: #have_enqueued_email, #enqueue_mail, #enqueue_email)
Passes if an email has been enqueued inside block.
-
#have_http_status(target) ⇒ Object
Passes if
response
has a matching HTTP status code. -
#have_performed_job(job = nil) ⇒ Object
(also: #perform_job)
Passes if a job has been performed inside block.
-
#receive_inbound_email(message) ⇒ Object
Passes if the given inbound email would be routed to the subject inbox.
-
#send_email(criteria = {}) ⇒ Object
Check email sending with specific parameters.
Instance Method Details
#be_a_new(model_class) ⇒ Object
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.
78 79 80 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 78 def be_a_new(model_class) BeANew.new(model_class) end |
#be_new_record ⇒ Object
Passes if actual returns true
for new_record?
.
25 26 27 |
# File 'lib/rspec/rails/matchers/be_new_record.rb', line 25 def be_new_record BeANewRecord.new end |
#be_valid(*args) ⇒ Object
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.
44 45 46 |
# File 'lib/rspec/rails/matchers/be_valid.rb', line 44 def be_valid(*args) BeValid.new(*args) end |
#have_been_enqueued ⇒ Object
Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
377 378 379 380 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 377 def have_been_enqueued check_active_job_adapter ActiveJob::HaveBeenEnqueued.new end |
#have_been_performed ⇒ Object
Passes if a job has been performed. May chain at_least, at_most or exactly to specify a number of times.
450 451 452 453 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 450 def have_been_performed check_active_job_adapter ActiveJob::HaveBeenPerformed.new end |
#have_broadcasted_to(target = nil) ⇒ Object Also known as: broadcast_to
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
.
48 49 50 51 52 |
# File 'lib/rspec/rails/matchers/action_cable.rb', line 48 def have_broadcasted_to(target = nil) check_action_cable_adapter ActionCable::HaveBroadcastedTo.new(target, channel: described_class) end |
#have_enqueued_job(job = nil) ⇒ Object 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.
342 343 344 345 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 342 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) ⇒ Object 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.
218 219 220 |
# File 'lib/rspec/rails/matchers/have_enqueued_mail.rb', line 218 def have_enqueued_mail(mailer_class = nil, mail_method_name = nil) HaveEnqueuedMail.new(mailer_class, mail_method_name) end |
#have_http_status(target) ⇒ Object
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
378 379 380 381 382 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 378 def have_http_status(target) raise ArgumentError, "Invalid HTTP status: nil" unless target HaveHttpStatus.matcher_for_status(target) end |
#have_performed_job(job = nil) ⇒ Object 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.
417 418 419 420 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 417 def have_performed_job(job = nil) check_active_job_adapter ActiveJob::HavePerformedJob.new(job) end |
#receive_inbound_email(message) ⇒ Object
Passes if the given inbound email would be routed to the subject inbox.
68 69 70 |
# File 'lib/rspec/rails/matchers/action_mailbox.rb', line 68 def receive_inbound_email() ActionMailbox::ReceiveInboundEmail.new() end |