A simple Ruby library that lets you manage your Mountebank test server.
Add this line to your application's Gemfile:
gem 'mountebank'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mountebank
Install Mountebank:
npm install -g mountebank --production
Start Mountebank:
mb --allowInjection
I recommend reading the Mountebank documentation for a deeper understanding of their API.
- Add these to you environment hash (eg. add to your
.env
file)
MOUNTEBANK_SERVER=127.0.0.1
MOUNTEBANK_PORT=2525
- Require the lib in your
spec_helper
.
require 'mountebank'
Mountebank.imposters
port = 4545
protocol = Mountebank::Imposter::PROTOCOL_HTTP
imposter = Mountebank::Imposter.create(port, protocol)
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
imposter = Mountbank.imposters.first
puts imposter.stubs
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
Behaviors can be passed through when creating a stub http response.
response = Mountebank::Stub::HttpResponse.create(status_code, headers, body, {wait: 1000}) # Wait 1 second before responding
The current set of specs require the Mountebank instance to be started with the --mock
flag.
- Fork it ( https://github.com/CoderKungfu/mountebank/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request