Class: RSpec::Hal::Matchers::TemplatedRelationMatcher
- Inherits:
-
Object
- Object
- RSpec::Hal::Matchers::TemplatedRelationMatcher
show all
- 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
HalMatcherHelpers::NullMatcher
Instance Attribute Summary
#repr
Instance Method Summary
collapse
#matcher?, #matcherize, #parse, #sentencize
Constructor Details
Returns a new instance of TemplatedRelationMatcher.
16
17
18
19
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 16
def initialize(link_rel, expected=NullMatcher)
@link_rel = link_rel.to_s
@expected = expected
end
|
Instance Method Details
#description ⇒ Object
60
61
62
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 60
def description
"have templated #{link_rel} link"
end
|
#failure_message ⇒ Object
Also known as:
failure_message_for_should
44
45
46
47
48
49
50
51
52
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 44
def failure_message
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
55
56
57
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 55
def failure_message_when_negated
"Expected `#{link_rel}` link to be absent or not templated"
end
|
#matches?(jsonish) ⇒ Boolean
Also known as:
===
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 21
def matches?(jsonish)
self.repr = jsonish
repr.raw_related_hrefs(link_rel){[]}
.tap{|it| if it.none?
@outcome = :no_relations
return false
end }
.select{|it| it.respond_to? :expand}
.tap{|it| if it.none?
@outcome = :no_templates
return false
end }
.select{|it| expected === it.pattern }
.tap{|it| if it.none?
@outcome = :none_matched
return false
end }
true
end
|
#uri_template ⇒ Object
69
70
71
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 69
def uri_template
repr.raw_related_hrefs(link_rel){[]}.first
end
|
#with_variables(*vars) ⇒ Object
Also known as:
with_variable
64
65
66
|
# File 'lib/rspec/hal/matchers/templated_relation_matcher.rb', line 64
def with_variables(*vars)
self.class.new(link_rel, UriTemplateHasVariablesMatcher.new(vars))
end
|