Class: RSpectacular::ActiveRecord::Matchers::PersistenceMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspectacular/matchers/active_record/persistence_matcher.rb

Instance Method Summary collapse

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, options)
  @persistable_class  = persistable.is_a?(Class) ? persistable : persistable.class
  @desired_attributes = options[:with] || persistable.attributes
  @desired_attributes = @desired_attributes.reject {|k,v| ['id', 'created_at', 'updated_at'].include? k}
end

Instance Method Details

#descriptionObject



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_messageObject



15
16
17
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 15

def failure_message
  "Expected to find an object saved with #{@desired_attributes}, didn't find one."
end

#matches?(subject) ⇒ Boolean

Returns:

  • (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_messageObject



19
20
21
# File 'lib/rspectacular/matchers/active_record/persistence_matcher.rb', line 19

def negative_failure_message
  "Didn't expect to find an object saved with #{@desired_attributes}, but got one anyway"
end