Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocking-server

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocking-server

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Mockery

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

(haven't published to rubygems) gem install mockery or add gem 'mockery' in your Gemfile

With rspec

  # in rspec helper
  require 'mockery'
  RSpec.configure do |config|
    config.include Mockery::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 'mockery'
  World(Mockery::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

FAQs

Package last updated on 17 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc