restful-matchers Build Status Code Climate Gem Version

RSpec matchers to test RESTful HATEOAS-compliant resource links. Currently it supports only JSON representations as an array of link objects with rel and href attributes.

Usage

Given the following JSON response:

{
  "attribute1": "value1",
  "attribute2": "value2",
  "links": [
    { "rel": "self", "href": "http://example.com" }
  ]
}

You can match links represented as an array of {rel: ... , href: ...} objects named as links:

describe MyRestfulController do
  render_views

  it "should have links" do
    get :index

    response.body.should have_link "resource1", "http://example.com/resource1"
    response.body.should have_link "resource2", "http://example.com/resource1"

    parsed_json = JSON.parse(response.body) # you can match both raw or parsed (hash) JSON
    parsed_json.should have_link "self"     # href attribute is optional
  end
end

Installation

Add it to the test group in your Gemfile and be happy!

gem 'restful-matchers', '~> 0.2', :group => :test