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/redirect_to.rb,
lib/rspec/rails/matchers/be_new_record.rb,
lib/rspec/rails/matchers/have_rendered.rb,
lib/rspec/rails/matchers/have_http_status.rb,
lib/rspec/rails/matchers/routing_matchers.rb
Overview
Container module for Rails specific matchers.
Defined Under Namespace
Modules: ActiveJob, HaveHttpStatus, RedirectTo, RenderTemplate, RoutingMatchers Classes: BeANew
Instance Method Summary (collapse)
-
- (Object) be_a_new(model_class)
Passes if actual is an instance of
model_classand returnstruefornew_record?. -
- (Object) be_new_record
Passes if actual returns
truefornew_record?. -
- (Object) be_valid(*args)
Passes if the given model instance's
valid?method is true, meaning all of theActiveModel::Validationspassed and no errors exist. -
- (Object) have_been_enqueued
Passes if a job has been enqueued.
-
- (Object) have_enqueued_job(job = nil)
(also: #enqueue_job)
Passes if a job has been enqueued inside block.
-
- (Object) have_http_status(target)
Passes if
responsehas a matching HTTP status code.
Instance Method Details
- (Object) 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.
77 78 79 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 77 def be_a_new(model_class) BeANew.new(model_class) end |
- (Object) be_new_record
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 |
- (Object) 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.
44 45 46 |
# File 'lib/rspec/rails/matchers/be_valid.rb', line 44 def be_valid(*args) BeValid.new(*args) end |
- (Object) have_been_enqueued
Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times.
267 268 269 270 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 267 def have_been_enqueued check_active_job_adapter ActiveJob::HaveBeenEnqueued.new end |
- (Object) 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.
235 236 237 238 |
# File 'lib/rspec/rails/matchers/active_job.rb', line 235 def have_enqueued_job(job = nil) check_active_job_adapter ActiveJob::HaveEnqueuedJob.new(job) end |
- (Object) 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::TestResponsealiases::error:missing:redirect:success
358 359 360 361 |
# File 'lib/rspec/rails/matchers/have_http_status.rb', line 358 def have_http_status(target) raise ArgumentError, "Invalid HTTP status: nil" unless target HaveHttpStatus.matcher_for_status(target) end |