class RESTful::Matchers::HaveLinks

Public Class Methods

new(links) click to toggle source
# File lib/restful/matchers/have_links.rb, line 23
def initialize(links)
  @match_links = {}

  if links.is_a?(Array)
    links.each do |link|
      rel  = link[:rel]  || link["rel"]
      href = link[:href] || link["href"]
      if rel
        @match_links[rel.to_s] = href
      else
        raise ::Errors::InvalidLink("Link has no `rel`: #{link}")
      end
    end
  else
    raise ArgumentError.new("matcher expects an array of hashes containing `rel` and `href` keys as argument")
  end
end

Public Instance Methods

failure_message_for_should() click to toggle source
# File lib/restful/matchers/have_links.rb, line 55
def failure_message_for_should
  "Expected links weren't found. #{content_and_match_links_message}"
end
failure_message_for_should_not() click to toggle source
# File lib/restful/matchers/have_links.rb, line 59
def failure_message_for_should_not
  "Not expected links where found. #{content_and_match_links_message}"
end
matches?(content) click to toggle source
# File lib/restful/matchers/have_links.rb, line 41
def matches?(content)
  @content = content
  @content_links = RESTful::Matchers::Parsers::JSONLinkParser.parse(content)
  if @content_links
    @content_links.each do |rel, href|
      match = href ? @match_links[rel] == href : @match_links.has_key?(rel)
      return false unless match
    end
    return true
  else
    return false
  end
end

Private Instance Methods