GithubHelp home page GithubHelp logo

siliconsenthil / mountebank-gem Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coderkungfu/mountebank-gem

0.0 2.0 0.0 251 KB

Ruby GEM to manage a Mountebank Test Server

License: MIT License

Ruby 100.00%

mountebank-gem's Introduction

Mountebank

A simple Ruby library that lets you manage your Mountebank test server.

Installation

Add this line to your application's Gemfile:

gem 'mountebank'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mountebank

Usage

Pre-Requisite

Install Mountebank:

npm install -g mountebank --production

Start Mountebank:

mb --allowInjection

I recommend reading the Mountebank documentation for a deeper understanding of their API.

Initialization

  1. Add these to you environment hash (eg. add to your .env file)

MOUNTEBANK_SERVER=127.0.0.1 MOUNTEBANK_PORT=2525


2. Include the lib in your `spec_helper`.

	```ruby
include 'mountebank'

Get all available imposters

Mountebank.imposters

Create Imposter

port = 4545
protocol = Mountebank::Imposter::PROTOCOL_HTTP
imposter = Mountebank::Imposter.create(port, protocol)

Create Imposter with Stub

port = 4545
protocol = Mountebank::Imposter::PROTOCOL_HTTP
imposter = Mountebank::Imposter.build(port, protocol)

# Create a response
status_code = 200
headers = {"Content-Type" => "application/json"}
body = {foo:"bar"}.to_json
response = Mountebank::Stub::HttpResponse.create(status_code, headers, body)

imposter.add_stub(response)
imposter.save!

Check the URL:

curl http://127.0.0.1:4545

Get all stubs

imposter = Mountbank.imposters.first
puts imposter.stubs

Create Imposter with Stub & Predicate

port = 4545
protocol = Mountebank::Imposter::PROTOCOL_HTTP
imposter = Mountebank::Imposter.build(port, protocol)

# Create a response
status_code = 200
headers = {"Content-Type" => "application/json"}
body = {foo:"bar2"}.to_json
response = Mountebank::Stub::HttpResponse.create(status_code, headers, body)

# Create a predicate
data = {equals: {path:"/test"}}
predicate = Mountebank::Stub::Predicate.new(data)

imposter.add_stub(response, predicate)
imposter.save!

Check the URL:

curl http://127.0.0.1:4545/test

Contributing

  1. Fork it ( https://github.com/CoderKungfu/mountebank/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

mountebank-gem's People

Contributors

miccheng 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.