No commit activity in last 3 years
No release in over 3 years
Rspec::RoarMatchers is a collection of matchers designed to enforce a contract between your spec and representer.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
~> 0.12.3
>= 0
 Project Readme

Rspec::RoarMatchers

Rspec::RoarMatchers is a collection of matchers designed to enforce a contract between your spec and representer. The driving concern while recently developing for an app that was making extensive use of Roar, was the fact that we were able to modify the various representers without the spec complaining.

So to ensure that any change to the representation of an object was explicit we made a few rspec matchers to do the heavy lifting.

Usage

Below are the matchers we've defined thus far (will likely be expanding). For more information regarding implementation see spec/roar_matchers/matchers_spec.rb.

The will enforce bi-directionally. This means that it will fail if:

  • if a property/collection/link is present in the representer but not in the spec
  • if a property/collection/link is present in the spec but not in the representer

All of these matchers receive a word array as an argument.

have_collections

context "collection is present in both spec and representer (happy path)" do
  it "passes" do
    expected_collections = %w{state_or_provinces}
    expect(country.extend(CountryRepresenter)).to have_collections(expected_collections)
  end
end

have_links

context "link is present in both spec and representer (happy path)" do
  it "passes" do
    expected_links = %w{self}
    expect(country.extend(CountryRepresenter)).to have_links(expected_links)
  end
end

have_properties

context "property is present in both spec and representer (happy path)" do
  it "passes" do
    expected_properties = %w{name}
    expect(country.extend(CountryRepresenter)).to have_properties(expected_properties)
  end
end

Installation

Add this line to your application's Gemfile:

gem 'rspec-roar_matchers'

And then execute:

$ bundle

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request