Class: RSpec::Hal::Matchers::TemplatedRelationMatcher
- Inherits:
-
Object
- Object
- RSpec::Hal::Matchers::TemplatedRelationMatcher
- Includes:
- HalMatcherHelpers
- Defined in:
- lib/rspec/hal/matchers/templated_relation_matcher.rb
Overview
Example
expect(doc).to have_templated_relation("search")
expect(doc).to have_templated_relation("search", matching("{?q}"))
Constant Summary
Constants included from HalMatcherHelpers
HalMatcherHelpers::NullMatcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
-
#initialize(link_rel, expected = NullMatcher) ⇒ TemplatedRelationMatcher
constructor
A new instance of TemplatedRelationMatcher.
- #matches?(jsonish) ⇒ Boolean
Methods included from HalMatcherHelpers
#matcher?, #matcherize, #parse, #sentencize
Constructor Details
#initialize(link_rel, expected = NullMatcher) ⇒ TemplatedRelationMatcher
Returns a new instance of TemplatedRelationMatcher.
13 14 15 16 |
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 13 def initialize(link_rel, expected=NullMatcher) @link_rel = link_rel @expected = expected end |
Instance Method Details
#description ⇒ Object
52 53 54 |
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 52 def description "have templated #{link_rel} link" end |
#failure_message ⇒ Object Also known as: failure_message_for_should
36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 36 def but_clause = if outcome == :no_templates "found only non-templated links" else "found none" end sentencize "Expected templated `#{link_rel}` link", expected.description, "but #{but_clause}" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
47 48 49 |
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 47 def "Expected `#{link_rel}` link to be absent or not templated" end |
#matches?(jsonish) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 18 def matches?(jsonish) repr = parse(jsonish) repr.(link_rel){[]} .select{|it| it.respond_to? :expand} .select{|it| expected === it } .any? .tap do |outcome| @outcome = if outcome :pass elsif repr.(link_rel){[]}.any? :no_templates else :no_relations end end end |