Class: Webhookdb::SpecHelpers::Postgres::HaveRowMatcher
- Inherits:
-
Object
- Object
- Webhookdb::SpecHelpers::Postgres::HaveRowMatcher
- Includes:
- RSpec::Matchers
- Defined in:
- lib/webhookdb/spec_helpers/postgres.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(criteria) ⇒ HaveRowMatcher
constructor
A new instance of HaveRowMatcher.
- #matches?(model) ⇒ Boolean
- #with_attributes(attrs) ⇒ Object
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_message ⇒ Object
155 156 157 158 159 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 155 def 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.] if @matcher return "invalid message" end |
#failure_message_when_negated ⇒ Object
161 162 163 164 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 161 def 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
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 |