Add this line to your application's Gemfile:
gem 'contracto-rspec'
And then execute:
$ bundle
- Add following lines in your
rails_helper.rb
:
require 'contracto/rspec'
RSpec.configure do |config|
Contracto::RSpec.start!(git: 'https://github.com/{github_user}/{contract_repository_name}.git')
#...
end
- Test your API request by comparing its responses to contract responses:
require 'rails_helper'
RSpec.describe 'Users', type: :request do
describe 'GET /users' do
it do
get users_path
compare_json_with_contract!(ignore: [:id])
end
end
describe 'GET /users/:id' do
it do
get user_path(User.first)
compare_json_with_contract!(ignore: [:created_at, :updated_at])
end
end
end
- Fork it ( https://github.com/[my-github-username]/contracto-rspec/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