Skip to content

An httpbin like Rack app for RSpec

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt
Notifications You must be signed in to change notification settings

ninoseki/rspec-httpbin

Repository files navigation

rspec-httpbin

An httpbin like Rack app for RSpec.

Note

This implementation is forked from weapp/foxyrb.

Install

gem install rspec-httpbin

Usage

RSpec::HTTPBin is a Rack app. You can mount it like:

require 'capybara'
require 'rspec/httpbin'

let!(:server) do
  server = Capybara::Server.new(RSpec::HTTPBin)
  server.boot
  server
end

And do a test:

require 'http'

res = HTTP.get("#{server.base_url}/get")
json = JSON.parse(res.body.to_s)
expect(json['headers']['User-Agent']).to start_with('http.rb/')

The following API endpoints are supported:

  • /get (GET)
  • /post (POST)
  • /put (PUT)
  • /delete (DELETE)
  • /patch (PATCH)
  • /status/{status} (any HTTP method)

/get, /post, put, /delete and patch return an HTTP response with the following fields.

  • data: Request body.
  • files: Not implemented. TBD.
  • form: Form data.
  • json: JSON data.
  • args: Parsed query strings.
  • headers: Headers.
  • origin: Origin.
  • url: URL.

About

An httpbin like Rack app for RSpec

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Stars

Watchers

Forks

Packages

No packages published