0.0
No commit activity in last 3 years
No release in over 3 years
A quick way of mocking an external web service you want to consume.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

Mocking-Server

A quick way of mocking an external web service you want to consume. Inspired by moco, mock-server and sinatra.

Why

Integration, especially based on HTTP, e.g. web service, REST etc, is widlly used in most web development. When you write a feature that need to connect to an external web service You wonder how to test that. One option is to stub methods in Net::HTTP and equivalents, but by doing that you are tying yourself to an implementation detail. The ideal thing is to have a server running locally, Then serve different request for different response.

One thing I want to highlight is, rather than set up a global server which respond to all coming request, With mockery, you can set up different server for different testcase, spec or scenario.

Feature

  • Standalone server, test the real interaction.
  • Setup your mock server with sinatra's elegant DSL.

Get it

gem install mocking-server or add gem 'mocking-server' in your Gemfile

With rspec

  # in rspec helper
  require 'mocking_server'
  RSpec.configure do |config|
    config.include MockingServer::Methods
  end

  # in spec
  describe ApiCilent do
    subject { ApiCilent.new }

    it "should return hello" do
      server = mock_server do
        get '/greeting' do
          status 200
          body 'hello'
        end
      end

      server.run do
        expect(subject.greeting).to eq('hello')
      end
    end
  end

With cucumber

  #in env.rb
  require 'mocking_server'
  World(MockingServer::Methods)


  # in steps
  server = mock_server do
    get '/greeting' do
      status 200
      body 'hello'
    end
  end

  server.run do
    # steps that send request to the local mock sever
  end

License

MIT.

Contributor

  • Niu Yameng
  • Nicholas Ren