class RSpec::Hal::Matchers::RelationMatcher
Example
expect(doc).to have_relation("search") expect(doc).to have_relation("search", matching("{?q}"))
Attributes
expected[R]
link_rel[R]
tmpl_vars[R]
Public Class Methods
new(link_rel, *args)
click to toggle source
Signature
expect(doc).to have_relation link_rel expect(doc).to have_relation link_rel, href_matcher expect(doc).to have_relation link_rel, template_variables expect(doc).to have_relation link_rel, template_variables, href_matcher
# File lib/rspec/hal/matchers/relation_matcher.rb, line 19 def initialize(link_rel, *args) @link_rel = link_rel.to_s @tmpl_vars, @expected = *if args.empty? [{},NullMatcher] elsif args.size > 1 args elsif hashish? args.first [args.first, NullMatcher] else [{}, args.first] end end
Public Instance Methods
description()
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 51 def description "have #{link_rel} link or embedded" end
failure_message()
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 41 def failure_message sentencize "Expected `#{link_rel}` link or embedded", expected.description, "but found none" end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 46 def failure_message_when_negated "Expected `#{link_rel}` link to be absent" end
Also aliased as: failure_message_for_should_not
matches?(jsonish)
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 33 def matches?(jsonish) repr = parse(jsonish) !repr.related_hrefs(link_rel, tmpl_vars){[]} .select{|it| expected === it } .empty? end
with_href(expected)
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 55 def with_href(expected) self.class.new(link_rel, tmpl_vars, matcherize(expected)) end
Protected Instance Methods
hashish?(obj)
click to toggle source
# File lib/rspec/hal/matchers/relation_matcher.rb, line 63 def hashish?(obj) obj.respond_to?(:key?) && obj.respond_to?(:[]) end