Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Boot up a real server to serve testing replies

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages