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.



141
142
143
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 141

def initialize(criteria)
  @criteria = criteria
end

Instance Method Details

#failure_messageObject



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

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



161
162
163
164
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 161

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)


145
146
147
148
149
150
151
152
153
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 145

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



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

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