Library add improve test log, validate its according to your API documentation, show the documentation coverage with log.
Test log setting supports RSpec test and WebMock stubbing for Ruby On Rails application, API documentation supports API Blueprint and OpenAPI.
This reduces the costs of support, testers and analysts.
Telegram community for any Fitting related questions
Log
FITTING incoming request {"method":"POST","path":"/public/api/v1/inboxes/tEX5JiZyceiwuKMi1oN9Sf8S/contacts","body":{},"response":{"status":200,"content_type":"application/json","body":{"source_id":"00dbf18d-879e-47cb-ac45-e9aece266eb1","pubsub_token":"ktn6YwPus57JDf4e59eFPom5","id":3291,"name":"shy-surf-401","email":null,"phone_number":null}},"title":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb:9","group":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb","host":"www.example.com"}
FITTING outgoing request {"method":"POST","path":"/v1/organizations/org_id/meeting","body":{},"response":{"status":200,"content_type":"application/json","body":{"success":true,"data":{"meeting":{"id":"meeting_id","roomName":"room_name"}}}},"title":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb:50","group":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb","host":"api.cluster.dyte.in"}
validation
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.FFF..FFFFFFFFFF....F.......F...FF.....F...F....F..............................FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF.F..FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF........FFF...FFFF......FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF........FFFFFFFFFFF..FFFFFF..FFFFFFFFFFFFFFFFF.......FFFFFF.............FFFFFFFFFFFF....F........FFF.F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF............FF........FFF......FFFFFFFFFFFFFFFFFFFFFF....FFFFFF......F............FFFF........FFFFFFFFFFFFFF.....FFFFFFFFFFFFFFFFFFFFFFF..FF.....FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.....FF..........FFFFFFFFFFFFFFFFFF...FFFF...............F.F....FF..FFFFFFFF 1) Fitting::Doc::NotFound log error:host: www.example.commethod: POSTpath: /public/api/v1/inboxes/{inbox_identifier}/contactscode: 200content-type: application/jsonjson-schema: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "id": { "type": "integer", "description": "Id of the contact" }, "source_id": { "type": "string", "description": "The session identifier of the contact" }, "name": { "type": "string", "description": "Name of the contact" }, "email": { "type": "string", "description": "Email of the contact" }, "pubsub_token": { "type": "string", "description": "The token to be used to connect to chatwoot websocket" } }}body: { "source_id": "c9e8c31f-06df-49b4-8fb9-4466457ae65b", "pubsub_token": "Zgc7DEvaj5TkgZ1a4C7AvJXo", "id": 3293, "name": "restless-snowflake-670", "email": null, "phone_number": null}error [ "The property '#/email' of type null did not match the following type: string in schema e56b7e65-d70c-5f7a-a96c-982df5f8f2f7"]...804 examples, 565 failure, 0 pendingCoverage: 65.51%Add this line to your application's Gemfile:
gem'fitting'After that execute:
$ bundleOr install the gem by yourself:
$ gem install fittingFirstly, improve test.log.
To your spec_helper.rb:
require'fitting'Fitting.loggerDelete all files log/*.log and run rspec
You get more information about incoming and outgoing request in log/fitting*.log.
FITTING incoming request {"method":"POST","path":"/public/api/v1/inboxes/tEX5JiZyceiwuKMi1oN9Sf8S/contacts","body":{},"response":{"status":200,"content_type":"application/json","body":{"source_id":"00dbf18d-879e-47cb-ac45-e9aece266eb1","pubsub_token":"ktn6YwPus57JDf4e59eFPom5","id":3291,"name":"shy-surf-401","email":null,"phone_number":null}},"title":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb:9","group":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb","host":"www.example.com"}
FITTING outgoing request {"method":"POST","path":"/v1/organizations/org_id/meeting","body":{},"response":{"status":200,"content_type":"application/json","body":{"success":true,"data":{"meeting":{"id":"meeting_id","roomName":"room_name"}}}},"title":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb:50","group":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb","host":"api.cluster.dyte.in"}
Secondly, validate the log to the documentation.
Add this to your .fitting.yml:
APIs:
- host: www.example.comtype: openapi2path: swagger/swagger.jsonRun
bundle e rake fitting:validateConsole output
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.FFF..FFFFFFFFFF....F.......F...FF.....F...F....F..............................FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF.F..FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF........FFF...FFFF......FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF........FFFFFFFFFFF..FFFFFF..FFFFFFFFFFFFFFFFF.......FFFFFF.............FFFFFFFFFFFF....F........FFF.F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF............FF........FFF......FFFFFFFFFFFFFFFFFFFFFF....FFFFFF......F............FFFF........FFFFFFFFFFFFFF.....FFFFFFFFFFFFFFFFFFFFFFF..FF.....FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.....FF..........FFFFFFFFFFFFFFFFFF...FFFF...............F.F....FF..FFFFFFFF 1) Fitting::Doc::NotFound log error:host: www.example.commethod: POSTpath: /public/api/v1/inboxes/{inbox_identifier}/contactscode: 200content-type: application/jsonjson-schema: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "id": { "type": "integer", "description": "Id of the contact" }, "source_id": { "type": "string", "description": "The session identifier of the contact" }, "name": { "type": "string", "description": "Name of the contact" }, "email": { "type": "string", "description": "Email of the contact" }, "pubsub_token": { "type": "string", "description": "The token to be used to connect to chatwoot websocket" } }}body: { "source_id": "c9e8c31f-06df-49b4-8fb9-4466457ae65b", "pubsub_token": "Zgc7DEvaj5TkgZ1a4C7AvJXo", "id": 3293, "name": "restless-snowflake-670", "email": null, "phone_number": null}error [ "The property '#/email' of type null did not match the following type: string in schema e56b7e65-d70c-5f7a-a96c-982df5f8f2f7"]...804 examples, 565 failure, 0 pendingCoverage: 65.51%And task will create HTML (coverage/fitting.html) reports.
More information on action coverage
Swagger
APIs:
- host: www.example.comtype: openapi2path: doc/api.jsonAlso OpenAPI
APIs:
- host: www.example.comtype: openapi3path: doc/api.jsonFirst you need to install drafter or crafter. Works after conversion from API Blueprint to API Elements (in YAML file) with Drafter or Crafter.
That is, I mean that you first need to do this
drafter doc.apib -o doc.yamlor
node_modules/.bin/crafter doc.apib > doc.yamland then
APIs:
- host: www.example.comtype: drafterpath: doc/api.yamlor
APIs:
- host: www.example.comtype: crafterpath: doc/api.yamlTo use additional features of the pre-converted tomograph
example
bundle exec tomograph -d crafter --exclude-description doc/api.yml doc/api.jsonand then
APIs:
- host: www.example.comtype: tomogrampath: doc/api.jsonSetting the prefix name is optional. For example, you can do this:
APIs:
- host: www.example.comprefix: /api/v3type: openapi2path: swagger/swagger.jsonIt is not necessary to immediately describe each host in detail, you can only specify its name and skip it until you are ready to documented it
SkipValidation:
- host: api.cluster.dyte.inIf you want to skip a specific prefix in the host
SkipValidation:
- host: api.cluster.dyte.inprefix: /admin/apiIf you want to skip a specific request in the host
SkipValidation:
- host: api.cluster.dyte.inmethod: GETpath: /api/v1/carsIt is not necessary to immediately test each doc in detail, you can only specify its name and skip it until you are ready to test it
NoCov:
- host: sso.testNoCov:
- host: sso.testmethod: GETNoCov:
- host: sso.testmethod: GETpath: /users/{userId}NoCov:
- host: sso.testmethod: GETpath: /users/{userId}code: 200NoCov:
- host: sso.testmethod: GETpath: /users/{userId}code: 200content-type: application/jsonNoCov:
- host: sso.testmethod: GETpath: /users/{userId}code: 200content-type: application/jsoncombination: oneOf.0NoCov:
- host: sso.testmethod: GETpath: /users/{userId}code: 200content-type: application/jsoncombination: oneOf.0combination_next: oneOf.0.required.usersIf you find bug, you can debug it or create task in this github project with new file coverage/fitting.debug.yml
Debug:
- host: www.example.commethod: GETpath: /api/v3/userscode: 200content-type: application/jsonJoin us on Telegram.
Bug reports and pull requests are welcome on GitHub at github.com/tuwilof/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.
The gem is available as open source under the terms of the MIT License.




