Module: Salestation::RSpec::Matchers
- Defined in:
- lib/salestation/rspec.rb
Overview
Usage:
In your RSpec configuration first include the matchers:
RSpec.configure do |config|
config.include Salestation::RSpec::Matchers
end
Then you can use the matchers like this:
expect(result).to be_failure
.with_conflict
.containing(message: 'Oh noes')
or when using Glia Errors:
expect(result).to be_failure
.with_requested_resource_not_found
.containing(Glia::Errors::ResourceNotFoundError.new(resource: :user))
or when matching input errors from Glia Errors:
expect(result).to be_failure
.with_invalid_input
.containing(glia_input_validation_error.on(:name).with_type(Glia::Errors::INVALID_VALUE_ERROR))
or you could even match multiple input errors at the same time:
expect(result).to be_failure
.with_invalid_input
.containing(
glia_input_validation_error
.on(:name).with_type(Glia::Errors::INVALID_VALUE_ERROR)
.on(:email)
.on(:phone_number).with_type(Glia::Errors::INVALID_FORMAT_ERROR)
)
also has support for nested errors:
nesting can be represented by calling `on` method with multiple arguments, for example when
you have a hash like
{
nested: {
name: ''
}
}
Then you can call it like glia_input_validation_error.on(:nested, :name)
expect(result).to be_failure
.with_invalid_input
.containing(
glia_input_validation_error
.on(:nested, :name).with_type(Glia::Errors::INVALID_VALUE_ERROR)
)
Everything after be_failure is optional. You could also use ‘.containing` multiple times like this:
expect(result).to be_failure
.containing(Glia::Errors::ResourceNotFoundError.new(resource: :user))
.containing(hash_including(message: 'Overriden message'))
Instance Method Summary collapse
Instance Method Details
#be_failure ⇒ Object
72 73 74 |
# File 'lib/salestation/rspec.rb', line 72 def be_failure FailureMatcher.new end |
#glia_input_validation_error ⇒ Object
76 77 78 |
# File 'lib/salestation/rspec.rb', line 76 def glia_input_validation_error GliaInputValidationErrorMatcher.new end |