No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0

Runtime

~> 2.0
 Project Readme

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

Let's say we have a MyRestfulController#index controller action that returns the following JSON representation, with links represented as an array of {rel: ... , href: ...} objects:

{
  "attribute1": "value1",
  "attribute2": "value2",
  "links": [
    { "rel": "foo", "href": "http://example.com/foo" }
    { "rel": "bar", "href": "http://example.com/bar" }
    { "rel": "baz", "href": "http://example.com/baz" }
    { "rel": "qux", "href": "http://example.com/qux" }
  ]
}

You can match those links using have_link or have_links matchers as follow:

describe MyRestfulController do
  render_views # don't forget this!

  it "should have links" do
    get :index
    
    # you can match against both raw ...
    response.body.should have_link "foo", "http://example.com/foo"
    response.body.should have_link "bar", "http://example.com/bar"

    # ... or parsed JSON (as a Hash)
    parsed_json = JSON.parse(response.body)

    # href attribute is optional
    parsed_json.should have_link "baz"

    # match many links at once using have_links matcher
    response.body.should have_links([
      { rel: "foo", href: "http://example.com/foo" },
      { rel: "bar", href: "http://example.com/bar" },
      { rel: "baz", href: "http://example.com/baz" },
      { rel: "qux", href: "http://example.com/qux" },
    ])
  end
end

Installation

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

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

Changelog

See CHANGELOG.

License

restful-matchers is Copyright © 2013 Marcos Hack. It is free software, and may be redistributed under the terms specified in the LICENSE file.