Class: RSpec::Rails::Matchers::BeANew
- Inherits:
-
Matchers::BuiltIn::BaseMatcher
- Object
- Matchers::BuiltIn::BaseMatcher
- RSpec::Rails::Matchers::BeANew
- Defined in:
- lib/rspec/rails/matchers/be_a_new.rb
Instance Method Summary (collapse)
- - (Object) failure_message_for_should private
-
- (BeANew) initialize(expected)
constructor
A new instance of BeANew.
- - (Boolean) matches?(actual) private
-
- (Object) with(expected_attributes)
Use this to specify the specific attributes to match on the new record.
Constructor Details
- (BeANew) initialize(expected)
Returns a new instance of BeANew
4 5 6 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 4 def initialize(expected) @expected = expected end |
Instance Method Details
- (Object) failure_message_for_should
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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 28 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 |
- (Boolean) matches?(actual)
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.
9 10 11 12 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 9 def matches?(actual) @actual = actual actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end |
- (Object) with(expected_attributes)
Use this to specify the specific attributes to match on the new record.
22 23 24 25 |
# File 'lib/rspec/rails/matchers/be_a_new.rb', line 22 def with(expected_attributes) attributes.merge!(expected_attributes) self end |