/rspec_api_helpers

Rspec test helpers for APIs.

Primary LanguageRubyMIT LicenseMIT

RspecApiHelpers

Gem Version Build Status Code Climate

This is a Gem to help you with all of you Rails API testing woes. The goal is to provide functionality to make testing APIs a breeze. I hope you like it!

Add this to your Gemfile:

gem 'rspec_api_helpers'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec_api_helpers

Include it in your spec_helper

RSpec.configure do |config|
  # ...
  config.include RspecApiHelpers
  # ...
end

Usage

  1. Built it strategy for coercing FactoryGirl factories into json:
FactoryGirl.json :user, name: 'Mrs. Mock', email: 'test@test.com'
# => {\"name\":\"Mrs. Mock\",\"email\":\"test@test.com\"}"
  1. Ready-to-fire headers:
headers_for :json
# => { 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' }
  1. Automatic JSON parsing for response.body:
# Call this in your spec
response_body
  1. Hash with indifferent access by default when parsing JSON:
parse_json response.body
# => can now use user[:email], etc.

Installation

Add this line to your application's Gemfile:

gem 'rspec_api_helpers'

Contributing

  1. Fork it ( https://github.com/sweatshirtio/rspec_api_helpers/fork )
  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 a new Pull Request