{"id":16955559,"url":"https://github.com/rcdexta/cucoo","last_synced_at":"2025-07-02T12:32:48.665Z","repository":{"id":28393040,"uuid":"31907294","full_name":"rcdexta/cucoo","owner":"rcdexta","description":"Cucumber steps and assertions for testing your APIs","archived":false,"fork":false,"pushed_at":"2018-06-27T18:12:44.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-15T22:31:31.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcdexta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-09T15:46:02.000Z","updated_at":"2018-06-27T18:12:46.000Z","dependencies_parsed_at":"2022-09-03T14:41:31.335Z","dependency_job_id":null,"html_url":"https://github.com/rcdexta/cucoo","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/rcdexta/cucoo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdexta%2Fcucoo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdexta%2Fcucoo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdexta%2Fcucoo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdexta%2Fcucoo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcdexta","download_url":"https://codeload.github.com/rcdexta/cucoo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcdexta%2Fcucoo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263140617,"owners_count":23419916,"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":[],"created_at":"2024-10-13T22:12:39.368Z","updated_at":"2025-07-02T12:32:48.632Z","avatar_url":"https://github.com/rcdexta.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cucoo\n\n[![Build Status](https://travis-ci.org/rcdexta/cucoo.svg)](https://travis-ci.org/rcdexta/cucoo)\n[![Gem Version](https://badge.fury.io/rb/cucoo.svg)](http://badge.fury.io/rb/cucoo)\n\nCucumber steps and assertions for testing your APIs. This gem offers a DSL on top of webmock, cucumber and json_spec to make testing APIs on rails easier.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cucoo'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install cucoo\n\n## Configuration\n\nCucoo comes as a package with the following gems installed\n\n* [json_spec](https://github.com/collectiveidea/json_spec)\n* [cucumber](https://github.com/cucumber/cucumber-rails)\n* [webmock](https://github.com/bblimke/webmock)\n\nA typical env.rb would look like this:\n \n```ruby\nrequire 'cucumber/rails'\nrequire 'cucoo/rails'\n\nActionController::Base.allow_rescue = false\n\nrequire File.expand_path('../../../config/environment', __FILE__)\n\nCapybara.default_driver = :selenium\n\nCucumber::Rails::Database.javascript_strategy = :truncation\n\nCucoo.config do |config|\n  config.app_port = 6666\n  config.stub_host = 'localhost'\n  config.stub_port = 4080\nend\n```\n\nThis will start your application on port 6666 on localhost and assume the external services are stubbed at specified host and port.\n\n## Ping Pong Test\nOur app responds to a url `/health/ping.json` with ping. The test to assert this is as follows\n```cucumber\nScenario: Health Checker\n    Given I make a GET to \"/health/ping.json\"\n    Then the response should be OK\n    And the response body must be \"pong\"\n```\n\n## More examples\n\nIn all the examples, lets assume we are asserting calls to an external service with the url `/external_service/***`\n\n1) Simple hello world service that accepts two post body params `message` and `says` and calls an external service. \n```cucumber\nScenario: Post Hello World\n    Given I expect a POST to \"/external_service/post_hello\" with:\n      | request                                   |\n      | {\"message\":\"Hello World\", \"says\": \"John\"} |\n    When I make a POST to \"/hello_world\" with:\n      | message     | says |\n      | Hello World | John |\n    Then the response should be OK\n```\n\nThe last line does two things. It checks if the response code is 200 and also if the expectations were satisfied. So, this must be called at the end of each scenario.\n\n2) Let's build on top of previous example and let the app return back what the external service returns.\n\n```cucumber\nScenario: Post Hello World and accept response\n    Given I expect a POST to \"/external_service/post_hello\" with:\n      | request                                  | response                                |\n      | {\"message\":\"Hello World\",\"says\": \"John\"} | {\"reply\":\"Get some life John\"}         |\n    When I make a POST to \"/hello_world\" with:\n      | message     | says |\n      | Hello World | John |\n    Then the response should be OK\n    Then the JSON should be:\n    \"\"\"\n    {\n       \"reply\": \"Get some life John\"\n    }\n    \"\"\"\n```\n\nNote that if the response from an external service is huge and can be read from a file, the POST expectation step can read from the file\n\n```cucumber\nGiven I expect a POST to \"/external_service/post_hello\" with:\n      | request                                  | file                                |\n      | {\"message\":\"Hello World\",\"says\": \"John\"} | stub/json/hello_world/response.json |\n```\n\nThe file will be read relative to the rails root path.\n\n3) Asserting a request body larger than hello world.\n\n```cucumber\nScenario: Add a new movie\n    Given I expect a POST to \"/external_service/add_movie\" with json request:\n    \"\"\"\n     {\n        \"name\": \"The Godfather\",\n        \"director\": \"Francis Coppola\",\n        \"year\": 1972,\n        \"rating\": 9.2,\n        \"runtime\": 175\n     }\n    \"\"\"\n    When I make a POST to \"/movies\" with:\n      | name          | director        | year | rating | runtime | \n      | The Godfather | Francis Coppola | 1972 | 9.2    | 175     |\n    Then the response should be OK\n```\n\n4) GET and json assertions\n\n```cucumber\nScenario: Get next token number\n    Given I expect a GET to \"/external_service/next_free_slot\" with:\n    | response                                           |\n    | {\"number\": 42, \"stats\": {\"total\": 110, \"free\": 54} |\n    When I make a GET to \"/next_id\"\n    Then the response should be OK\n    And the JSON response at \"stats\" should be:\n    \"\"\"\n    {\"total\": 110, \"free\": 54}\n    \"\"\"\n```\n\nIn the above example, we have seen a slightly advanced version of asserting for json response. Please refer [json_spec doc](https://github.com/collectiveidea/json_spec#cucumber) for more examples of json response assertion.\n\nWe can also check for other response codes:\n\n```cucumber\nThen the response should be NOT FOUND #404\nThen the response should be BAD REQUEST #400\nThen the response code should be \"302\" #custom response code\n```\n\n5) PUT request\n\n```cucumber\nScenario: Update employee details\n    Given I expect a PUT to \"/external_service/employee/\" with json request:\n    \"\"\"\n        {\n            \"id\": 812,\n            \"name\": \"Steve Balmer\",\n            \"status\": \"unemployed\"\n        }\n    \"\"\"\n    When I make a PUT to \"employees\" with:\n    | id  | name          | status     |  \n    | 812 | Steve Balmer  | unemployed |\n    Then the response should be OK\n```\n\n6) DELETE request\n\n```cucumber\nScenario: Delete device token\n    Given I expect a DELETE to \"/external_service/device/ab112321adceadcdf\"\n    When I make a DELETE to \"devices\" with:\n    | token             |\n    | ab112321adceadcdf |\n    Then the response should be OK\n```\n\nThis gem is very much a work-in-progress. We will keep adding more assertions with usage. Contributions welcome\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/cucoo/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcdexta%2Fcucoo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcdexta%2Fcucoo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcdexta%2Fcucoo/lists"}