<commit_before># restful-matchers [![Build Status](https://travis-ci.org/marcoshack/restful-matchers.png?branch=master)](https://travis-ci.org/marcoshack/restful-matchers) [![Code Climate](https://codeclimate.com/github/marcoshack/restful-matchers.png)](https://codeclimate.com/github/marcoshack/restful-matchers) [![Gem Version](https://badge.fury.io/rb/restful-matchers.png)](http://badge.fury.io/rb/restful-matchers)

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, like this:

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

Example:

```ruby
describe MyRestfulController do
  render_views

  it "should have entry-point links" do
    get :index
    response.body.should have_link "resource1", "http://example.com/resource1"
    response.body.should have_link "resource2", "http://example.com/resource1"
  end

  it "should have self link, no matter its href" do
    parsed_json = JSON.parse(response.body) # you can match both raw or parsed (hash) JSON
    parsed_json.should have_link "resource2"
  end
end
```

## Installation

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

```ruby
group :test do
  gem 'restful-matchers'
end
```<commit_msg>README.md updated for version v0.2.0 [ci skip]<commit_after># restful-matchers [![Build Status](https://travis-ci.org/marcoshack/restful-matchers.png?branch=master)](https://travis-ci.org/marcoshack/restful-matchers) [![Code Climate](https://codeclimate.com/github/marcoshack/restful-matchers.png)](https://codeclimate.com/github/marcoshack/restful-matchers) [![Gem Version](https://badge.fury.io/rb/restful-matchers.png)](http://badge.fury.io/rb/restful-matchers)

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, like this:


## Usage

Given the following JSON response:

```json
{
  "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`:

```ruby
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!

```ruby
group :test do
  gem 'restful-matchers'
end
```
{'fraction_non_alphanumeric': 0.14483714483714483, 'fraction_numerical': 0.00693000693000693, 'mean_word_length': 4.426691729323308, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3152169', 'n_tokens_mistral': 991, 'n_tokens_neox': 961, 'n_words': 246}