0.03
Low commit activity in last 3 years
A long-lived project that still receives updates
Boot up a real server to serve testing replies
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

>= 0
 Project Readme

Boot up a real server to serve testing replies

Install

gem install stub_server

Usage

require 'stub_server'
require 'open-uri'

describe "Stub Server" do
  let(:port) { 9123 }
  let(:replies) { { "/hello" => [200, {}, ["World"]] } }
  
  it "can connect" do
    StubServer.open(port, replies) do |server|
      server.wait # ~ 0.1s
      URI.open("http://localhost:#{port}/hello").read.must_equal "World"
    end
  end
  
  it "fails on unknown paths" do
    StubServer.open(port, replies) do |server|
      server.wait
      assert_raises(OpenURI::HTTPError) { URI.open("http://localhost:#{port}/no").read }
    end
  end
end
  • Enable ssl ssl: {cert: File.read(cert), key: File.read(key)}
  • override other options by passing in WebBrick options, see lib/stub_server.rb
  • Use json: true to make all replies .to_json before sending, this is useful when modifying replies inside of tests

Author

Michael Grosser
michael@grosser.it
License: MIT
Build Status