Class: RSpectacular::ActiveRecord::Matchers::PersistenceMatcher
- Inherits:
-
Object
- Object
- RSpectacular::ActiveRecord::Matchers::PersistenceMatcher
- Defined in:
- lib/rspectacular/matchers/active_record/persistence_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(persistable, options) ⇒ PersistenceMatcher
constructor
A new instance of PersistenceMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(persistable, options) ⇒ PersistenceMatcher
Returns a new instance of PersistenceMatcher.
5 6 7 8 9 |
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 5 def initialize(persistable, ) @persistable_class = persistable.is_a?(Class) ? persistable : persistable.class @desired_attributes = [:with] || persistable.attributes @desired_attributes = @desired_attributes.reject {|k,v| ['id', 'created_at', 'updated_at'].include? k} end |
Instance Method Details
#description ⇒ Object
23 24 25 |
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 23 def description "should be an instance of #{@expected_class_name}" end |
#failure_message ⇒ Object
15 16 17 |
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 15 def "Expected to find an object saved with #{@desired_attributes}, didn't find one." end |
#matches?(subject) ⇒ Boolean
11 12 13 |
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 11 def matches?(subject) @persistable_class.where(@desired_attributes).first end |
#negative_failure_message ⇒ Object
19 20 21 |
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 19 def "Didn't expect to find an object saved with #{@desired_attributes}, but got one anyway" end |