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
- 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\"}"
- Ready-to-fire headers:
headers_for :json
# => { 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' }
- Automatic JSON parsing for
response.body
:
# Call this in your spec
response_body
- Hash with indifferent access by default when parsing JSON:
parse_json response.body
# => can now use user[:email], etc.
Add this line to your application's Gemfile:
gem 'rspec_api_helpers'
- Fork it ( https://github.com/sweatshirtio/rspec_api_helpers/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request