Class: RSpec::Rails::Matchers::BeANew
- Inherits:
-
Object
- Object
- RSpec::Rails::Matchers::BeANew
- Includes:
- Matchers::BaseMatcher
- Defined in:
- lib/rspec/rails/matchers/be_a_new.rb
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object private
- #matches?(actual) ⇒ Boolean private
-
#with(expected_attributes) ⇒ Object
Use this to specify the specific attributes to match on the new record.
Instance Method Details
#failure_message_for_should ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 25 def [].tap do || unless actual.is_a?(expected) && actual.new_record? << "expected #{actual.inspect} to be a new #{expected.inspect}" end unless attributes_match?(actual) if unmatched_attributes.size > 1 << "attributes #{unmatched_attributes.inspect} were not set on #{actual.inspect}" else << "attribute #{unmatched_attributes.inspect} was not set on #{actual.inspect}" end end end.join(' and ') end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 9 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 6 def matches?(actual) super actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end |
#with(expected_attributes) ⇒ Object
Use this to specify the specific attributes to match on the new record.
19 20 21 22 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 19 def with(expected_attributes) attributes.merge!(expected_attributes) self end |