{"id":14969346,"url":"https://github.com/hidroh/cucumber-api","last_synced_at":"2025-04-07T10:27:11.453Z","repository":{"id":27815868,"uuid":"31305411","full_name":"hidroh/cucumber-api","owner":"hidroh","description":"API validator in BBD style with Cucumber","archived":false,"fork":false,"pushed_at":"2021-03-25T11:37:30.000Z","size":36,"stargazers_count":52,"open_issues_count":9,"forks_count":54,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T08:12:18.492Z","etag":null,"topics":["api","bdd","cucumber","json","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/cucumber-api","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hidroh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-25T09:06:30.000Z","updated_at":"2024-04-16T11:59:03.000Z","dependencies_parsed_at":"2022-07-24T15:17:11.057Z","dependency_job_id":null,"html_url":"https://github.com/hidroh/cucumber-api","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hidroh%2Fcucumber-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hidroh%2Fcucumber-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hidroh%2Fcucumber-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hidroh%2Fcucumber-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hidroh","download_url":"https://codeload.github.com/hidroh/cucumber-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634479,"owners_count":20970533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bdd","cucumber","json","ruby","ruby-gem"],"created_at":"2024-09-24T13:41:43.666Z","updated_at":"2025-04-07T10:27:11.434Z","avatar_url":"https://github.com/hidroh.png","language":"Ruby","readme":"# cucumber-api\n[![Build Status](https://travis-ci.org/hidroh/cucumber-api.svg?branch=master)](https://travis-ci.org/hidroh/cucumber-api) [![Gem Version](https://badge.fury.io/rb/cucumber-api.svg)](http://badge.fury.io/rb/cucumber-api) [![Dependency Status](https://gemnasium.com/hidroh/cucumber-api.svg)](https://gemnasium.com/hidroh/cucumber-api)\n [![Code Climate](https://codeclimate.com/github/hidroh/cucumber-api/badges/gpa.svg)](https://codeclimate.com/github/hidroh/cucumber-api) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/cucumber-api?type=total)](https://rubygems.org/gems/cucumber-api)\n\nAPI validator in BDD style with [Cucumber](https://cukes.info/). **cucumber-api** lets one validate public APIs JSON response in blazingly fast time.\n\nInspired by [cucumber-api-steps](https://github.com/jayzes/cucumber-api-steps).\n\nCheckout [sample](/features/sample.feature) to see **cucumber-api** in action.\n\n## Installation\n\nAdd `cucumber-api` gem to your `Gemfile`:\n\n    gem 'cucumber-api'\n\nRequire `cucumber-api` in your Cucumber's `env.rb`:\n\n```ruby\nrequire 'cucumber-api'\n```\n\n## Configuration\n\n**Verbose logging:** enable verbose logging of API calls and responses by setting `cucumber_api_verbose=true` in your `ENV`, preferably via your `cucumber.yml`\n\n```yaml\n# config/cucumber.yml\n##YAML Template\n---\nverbose     : cucumber_api_verbose=true\n```\n\n## Usage\n\n### Available steps\n\n**Preparation steps**\n\nSpecify your request header's `Content-Type` and `Accept`. The only supported option for `Accept` is `application/json` at the moment.\n\n```gherkin\nGiven I send and accept JSON\nGiven I send \"(.*?)\" and accept JSON\n```\n\nYou could also others header's information like:\n\n```gherkin\nGiven I send and accept JSON\nAnd I add Headers:\n  | name1 | value |\n  | name2 | other |  \n```\n\nSpecify POST body\n\n```gherkin\nWhen I set JSON request body to '(.*?)'\nWhen I set form request body to:\n  | key1 | value1              |\n  | key2 | {value2}            |\n  | key3 | file://path-to-file |\nWhen I set JSON request body to:\n\"\"\"\n{\n  \"key1\": \"jsonString\",\n  \"key2\":  1\n}\n\"\"\"\n```\n\nOr from YAML/JSON file\n\n```gherkin\nWhen I set request body from \"(.*?).(yml|json)\"\n```\n\nExample:\n\n```Gherkin\nGiven I send \"www-x-form-urlencoded\" and accept JSON\nWhen I set JSON request body to '{\"login\": \"email@example.com\", \"password\": \"password\"}'\nWhen I set form request body to:\n  | login    | email@example.com     |\n  | password | password              |\nWhen I set request body from \"data/json-data.json\"\nWhen I set request body from \"data/form-data.yml\"\n```\n\n**Request steps**\n\nSpecify query string parameters and send an HTTP request to given URL with parameters\n\n```gherkin\nWhen I send a (GET|POST|PATCH|PUT|DELETE) request to \"(.*?)\"\nWhen I send a (GET|POST|PATCH|PUT|DELETE) request to \"(.*?)\" with:\n  | param1 | param2 | ... |\n  | value1 | value2 | ... |\n```\n\nTemporarily save values from the last request to use in subsequent steps in the same scenario:\n\n```gherkin\nWhen I grab \"(.*?)\" as \"(.*?)\"\n```\n\nOptionally, auto infer placeholder from grabbed JSON path:\n\n```gherkin\n# Grab and auto assign {id} as placeholder\nWhen I grab \"$..id\"\n```\n\nThe saved value can then be used to replace `{placeholder}` in the subsequent steps.\n\nExample:\n\n```gherkin\nWhen I send a POST request to \"http://example.com/token\"\nAnd I grab \"$..request_token\" as \"token\"\nAnd I grab \"$..access_type\" as \"type\"\nAnd I grab \"$..id\"\nAnd I send a GET request to \"http://example.com/{token}\" with:\n  | type            | pretty |\n  | {type}          | true   |\nThen the JSON response should have required key \"id\" of type string and value \"{id}\"\n```\n\nAssume that [http://example.com/token](http://example.com/token) have an element `{\"request_token\": 1, \"access_type\": \"full\", \"id\": \"user1\"}`, **cucumber-api** will execute the followings:\n\n* POST [http://example.com/token](http://example.com/token)\n* Extract the first `request_token`, `access_type` and `id` from JSON response and save it for subsequent steps\n* GET [http://example.com/1?type=full\u0026pretty=true](http://example.com/1?type=full\u0026pretty=true)\n* Verify that JSON response has a pair of JSON key-value: `\"id\": \"user1\"`\n* Clear all saved values\n\nThis will be handy when one needs to make a sequence of calls to authenticate/authorize API access.\n\n**Assert steps**\n\nVerify:\n* HTTP response status code\n* JSON response against a JSON schema conforming to [JSON Schema Draft 4](http://tools.ietf.org/html/draft-zyp-json-schema-04)\n* Adhoc JSON response key-value type pair, where key is a [JSON path](http://goessner.net/articles/JsonPath/)\n\n```gherkin\nThen the response status should be \"(\\d+)\"\nThen the JSON response should follow \"(.*?)\"\nThen the JSON response root should be (object|array)\nThen the JSON response should have key \"([^\\\"]*)\"\nThen the JSON response should have (required|optional) key \"(.*?)\" of type (numeric|string|boolean|numeric_string|object|array|any)( or null)\nThen the JSON response should have (required|optional) key \"(.*?)\" of type (numeric|string|boolean|numeric_string|object|array|any)( or null) and value \"(.*?)\"\n```\n\nExample:\n\n```gherkin\nThen the response status should be \"200\"\nThen the JSON response should follow \"features/schemas/example_all.json\"\nThen the JSON response root should be array\nThen the JSON response should have key \"id\"\nThen the JSON response should have optional key \"format\" of type string or null\nThen the JSON response should have required key \"status\" of type string and value \"foobar\"\n```\n\nAlso checkout [sample](/features/sample.feature) for real examples. Run sample with the following command:\n\n```\ncucumber -p verbose\n```\n\n### Response caching\n\nResponse caching is provided for GET requests by default. This is useful when you have a Scenario Outline or multiple Scenarios that make GET requests to the same endpoint.\n\nOnly the first request to that endpoint is made, subsequent requests will use cached response. Response caching is only available for GET method.\n\nThe response cache can also be cleared if needed:\n\n```gherkin\nGiven I clear the response cache\n```\n\n## Dependencies\n* [cucumber](https://github.com/cucumber/cucumber) for BDD style specs\n* [jsonpath](https://github.com/joshbuddy/jsonpath) for traversal of JSON response via [JSON path](http://goessner.net/articles/JsonPath/)\n* [json-schema](https://github.com/ruby-json-schema/json-schema) for JSON schema validation\n* [rest-client](https://github.com/rest-client/rest-client) for HTTP REST request\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhidroh%2Fcucumber-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhidroh%2Fcucumber-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhidroh%2Fcucumber-api/lists"}