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.
150 151 152 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 150 def initialize(criteria) @criteria = criteria end |
Instance Method Details
#failure_message ⇒ Object
164 165 166 167 168 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 164 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
170 171 172 173 |
# File 'lib/webhookdb/spec_helpers/postgres.rb', line 170 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
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 |