{"id":22112364,"url":"https://github.com/lukeredpath/mimic","last_synced_at":"2025-07-25T07:32:53.442Z","repository":{"id":1019953,"uuid":"847638","full_name":"lukeredpath/mimic","owner":"lukeredpath","description":"A Ruby gem for faking external web services for testing","archived":false,"fork":false,"pushed_at":"2022-11-30T23:58:19.000Z","size":111,"stargazers_count":152,"open_issues_count":11,"forks_count":26,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2023-11-07T20:41:36.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/lukeredpath.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","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":"2010-08-19T00:44:31.000Z","updated_at":"2023-07-14T23:28:20.000Z","dependencies_parsed_at":"2023-01-11T15:49:03.160Z","dependency_job_id":null,"html_url":"https://github.com/lukeredpath/mimic","commit_stats":null,"previous_names":[],"tags_count":6,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeredpath%2Fmimic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeredpath%2Fmimic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeredpath%2Fmimic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeredpath%2Fmimic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeredpath","download_url":"https://codeload.github.com/lukeredpath/mimic/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227544088,"owners_count":17785198,"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-12-01T10:57:42.725Z","updated_at":"2024-12-01T10:57:43.404Z","avatar_url":"https://github.com/lukeredpath.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mimic, simple web service stubs for testing [![Build Status](https://secure.travis-ci.org/lukeredpath/mimic.png)](https://secure.travis-ci.org/lukeredpath/mimic)\n\n## What is Mimic?\n\nMimic is a testing tool that lets you set create a fake stand-in for an external web service to be used when writing integration/end-to-end tests for applications or libraries that access these services.\n\n## Why not stub?\nThere are already some good tools, like [FakeWeb](http://fakeweb.rubyforge.org/) which let you stub requests at a low-level which is fine for unit and functional tests but when exercising our code through integration or end-to-end tests we want to exercise as much of the stack as possible.\n\nMimic aims to make it possible to test your networking code without actually hitting the real services by starting up a real web server and responding to HTTP requests. This lets you test your application against canned responses in an as-close-to-the-real-thing-as-possible way.\n\nAlso, because Mimic responds to real HTTP requests, it can be used when testing non-Ruby applications too.\n\n## Examples\n\nRegistering to a single request stub:\n\n    Mimic.mimic.get(\"/some/path\").returning(\"hello world\")\n    \nAnd the result, using RestClient:\n  \n    $ RestClient.get(\"http://www.example.com:11988/some/path\") # =\u003e 200 | hello world\n  \nRegistering multiple request stubs; note that you can stub the same path with different HTTP methods separately.\n\n    Mimic.mimic do\n      get(\"/some/path\").returning(\"Hello World\", 200)\n      get(\"/some/other/path\").returning(\"Redirecting...\", 301, {\"Location\" =\u003e \"somewhere else\"})\n      post(\"/some/path\").returning(\"Created!\", 201)\n    end\n    \nYou can even use Rack middlewares, e.g. to handle common testing scenarios such as authentication:\n\n    Mimic.mimic do\n      use Rack::Auth::Basic do |user, pass|\n        user == 'theuser' and pass == 'thepass'\n      end\n      \n      get(\"/some/path\")\n    end\n    \nFinally, because Mimic is built on top of Sinatra for the core request handling, you can create your stubbed requests like you would in any Sinatra app:\n\n    Mimic.mimic do\n      get \"/some/path\" do\n        [200, {}, \"hello world\"]\n      end\n    end\n\n## Using Mimic with non-Ruby processes\n\nMimic has a built-in REST API that lets you configure your request stubs over HTTP. This makes it possible to use Mimic from other processes that can perform HTTP requests.\n\nFirst of all, you'll need to run Mimic as a daemon. You can do this with a simple Ruby script and the [daemons](http://daemons.rubyforge.org/) gem:\n\n    #!/usr/bin/env ruby\n    require 'mimic'\n    require 'daemons'\n    \n    Daemons.run_proc(\"mimic\") do\n      Mimic.mimic(:port =\u003e 11988, :fork =\u003e false, :remote_configuration_path =\u003e '/api') do\n        # configure your stubs here\n      end\n    end\n    \nGive the script executable permissions and then start it:\n\n    $ your_mimic_script.rb start (or run)\n    \nThe remote configuration path is where the API endpoints will be mounted - this is configurable as you will not be able this path or any paths below it in your stubs, so choose one that doesn't conflict with the paths you need to stub.\n\nThe API supports both JSON and Plist payloads, defaulting to JSON. Set the request Content-Type header to application/plist for Plist requests.\n\nFor the following Mimic configuration (using the Ruby DSL):\n\n    Mimic.mimic.get(\"/some/path\").returning(\"hello world\")\n    \nThe equivalent stub can be configured using the REST API as follows:\n\n    $ curl -d'{\"path\":\"/some/path\", \"body\":\"hello world\"}' http://localhost:11988/api/get\n    \nLikewise, a POST request to the same path could be stubbed like so:\n\n    $ curl -d'{\"path\":\"/some/path\", \"body\":\"hello world\"}' http://localhost:11988/api/post\n\nThe end-point of the API is the HTTP verb you are stubbing, the path, response body, code and headers are specified in the POST data (a hash in JSON or Plist format). See the HTTP API Cucumber features for more examples.\n\nAn [Objective-C wrapper](http://github.com/lukeredpath/LRMimic) for the REST API is available, allowing you to use mimic for your OSX and iOS apps.\n\n## Contributors\n\n* [James Fairbairn](http://github.com/jfairbairn)\n* [Marcello Barnaba](https://github.com/vjt)\n\n## License\n\nAs usual, the code is released under the MIT license which is included in the repository.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeredpath%2Fmimic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeredpath%2Fmimic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeredpath%2Fmimic/lists"}