Class: Webhookdb::SpecHelpers::Postgres::HaveRowMatcher

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/webhookdb/spec_helpers/postgres.rb

Instance Method Summary collapse

Constructor Details

#initialize(criteria) ⇒ HaveRowMatcher

Returns a new instance of HaveRowMatcher.



150
151
152
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 150

def initialize(criteria)
  @criteria = criteria
end

Instance Method Details

#failure_messageObject



164
165
166
167
168
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 164

def failure_message
  return "Expected %s to have a row matching criteria %p but did not" % [@model.name, @criteria] unless @instance
  return "Row found but matcher failed with: %s" % [@matcher.failure_message] if @matcher
  return "invalid message"
end

#failure_message_when_negatedObject



170
171
172
173
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 170

def failure_message_when_negated
  return "Expected %s to not have a row matching criteria %p but did" % [@model.name, @criteria] if @instance
  return "invalid message"
end

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 154

def matches?(model)
  @model = model
  @instance = @model[@criteria]
  return false if @instance.nil?

  return @matcher.matches?(@instance) if @matcher

  return true
end

#with_attributes(attrs) ⇒ Object



175
176
177
178
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 175

def with_attributes(attrs)
  @matcher = RSpec::Matchers::BuiltIn::HaveAttributes.new(attrs)
  return self
end