Giter Site home page Giter Site logo

ruffian's Introduction

Ruffian

What

Ruffian is a hapi-based server that allows developers to easily set up fake servers for isolated testing.

Why

There are, of course, alternatives to isolating your tests from external components:

  • you can isolate the modules in your code that interact with external services and mock them (using sinon, for example);

  • you can use a library that mocks the http library itself (such as nock);

These approaches have their cases for best usage and the purpose here is not to prove that setting up a fake server is a better approach. But there are situations in which this leads you to a better test structure.

If you are leveraging practices such as:

  1. using contract-driven tests to check your external dependencies;
  2. using a service composition tool such as docker-compose to set up your target environment;

then ruffian may be the tool for you. Use the contracts from item #1 to set up your request/response expectations, bring a ruffian app within a container so that you can manually exercise your code, in case you choose to.

How: installation

You can install ruffian as a global tool:

npm install -g ruffian

And then start it through the cli:

ruffian

You can also clone this repo and start the server by doing:

npm install
npm start

How: setting up fakes through the CLI

You can pass a JSON file to the CLI:

ruffian -f fakes.json

Ruffian expects the file to contain an array of objects, each with the following attributes:

  • method: the HTTP verb to respond to. Possible values: GET, POST, PATCH, PUT, HEAD, OPTIONS
  • path: route from ruffians root "/". All routes must start with a backslash. Ruffian accepts any format supported by hapi
  • payload: the payload Ruffian should return when the endpoint is exercised

How: setting up fakes through the REST interface

Once the server is running, you can configure behavior by posting data to the ruffian/fakes endpoint:

curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: ea3a34e1-ee5b-53a6-59e5-caf6fe5bc400" -d '{
	"method": "GET",
	"path": "/foo",
	"payload": "bar!"
}' "http://localhost:3000/ruffian/fakes"

How: setting up fakes through the module

TO-DO: finish lib handling and document how-to

ruffian's People

Contributors

dclucas avatar

Watchers

 avatar James Cloos avatar

ruffian's Issues

Rename README file

Hello, you could rename README file to README.md so github would hander it as HTML. At least I think so.

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.