Fitting
This gem will help to realize your API in strict accordance with the documentation in the format API Bluprint. To do this, when you run your RSpes tests on the controller, in the documentation automatically searches for the json-schema and then validate it with a response in the test.
Installation
Add this line to your application's Gemfile:
gem 'fitting'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fitting
Usage
In your spec_helper.rb:
Fitting.configure do |config|
config.apib_path = `doc.apib`
end
Example output
After running tests you will get statistics in the console.
Fully conforming requests:
DELETE /api/v1/book
Matchers
If you want know describe why you get crosses instead of checkmarks you can use matchers for RSpec.
match_response
Makes a simple validation JSON Schema.
expect(response).to match_response
strict_match_response
Makes a strict validation JSON Schema. All properties are condisidered to have "required": true and all objects "additionalProperties": false.
expect(response).to strict_match_response
Config
apib_path
Path for API Blueprint documentation. There must be an installed library drafter.
drafter_yaml_path
Path for API Blueprint documentation after use drafter and transformation in yaml.
necessary_fully_implementation_of_responses
Default true. It returns exit 1 if not implemented all(with tests expect match response) the responses.
strict
Default false. If true than all properties are condisidered to have "required": true and all objects "additionalProperties": false.
prefix
Prefix for request.
white_list
Default all resources. This is an array of resources that are mandatory for implementation. This list does not affect the work of the match expert. This list is only for the report in the console and verify implementation.
config.white_list = {
'/users' => ['DELETE', 'POST'],
'/users/{id}' => ['GET', 'PATCH'],
'/users/{id}/employees' => ['GET'],
'/sessions' => []
}
Empty array [] means all methods.
Result be two statistic for two list.
create_report_with_name
Create report with name.
show_statistics_in_console
Default true.
Report
Autogenerate report_request_by_response.yaml and report_response.yaml reports.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/funbox/fitting. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.