Giter VIP home page Giter VIP logo

restspy's Introduction

RESTSpy

Mock REST endpoints or proxy them to real endpoints.

Spies

A Spy is a local proxy server that by default redirects requests to any endpoint to another server.

In a test setup you will create a Spy for every REST service that your application depends on and that you want to spy on.

Once a Spy is created, you can start mocking certain endpoints, by providing Doubles. A Double represents a HTTP response as a triplet of a status code, headers and body.

Examples

Mock http://localhost:1234/stream endpoint, while requests to all other endpoints are proxied to https://www.facebook.com

facebook = RestSpy::Spy.server_on_local_port('https://www.facebook.com', 1234)
facebook.endpoint('/stream').should_return('Hello world!')

Endpoints can also be matched using a regular expression. The following example shows how to mock all endpoints on localhost:1234 that start with stream.

facebook.endpoint('/stream.*').should_return(`Hello world!`, headers={'Token' => 'abcd'})

Simulate an error code on the http://localhost:1234/search endpoint, while requests to all other endpoints are proxied to http://www.google.com

google = RestSpy::Spy.server_on_local_port('http://www.google.com', 1234)
google.endpoint('/search').should_return_error_code 401

restspy's People

Contributors

ybonjour avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.