Documentation
About
HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making requests
from Ruby. RSpec is a Behaviour Driven Development spec libary for Ruby. Making TDD
Productive and Fun.
This gem adds custom matchers to make it easier to check http requests.
Installation
Add the gem to your gemfile with bundler
$ bunlde add http-rspec --require
or manually
gem "http-rspec", require: false
Inside of your spec helper (default spec_helper.rb):
require "http/rspec"
Now you have to include the matchers you want for the blocks you want
RSpec.configure do |config|
config.include HTTP::Support::RspecMatchers
end
RSpec.configure do |config|
config.include HTTP::Support::RspecMatchers, type: :service
end
RSpec.describe Service do
include HTTP::Support::RspecMatchers
it "makes request" do
expect(response).to be_an_http_gem_response.with(status: 200)
end
end
Documentation
Most things are documented here in the readme
The following API documentation is also available:
Basic Usage
Here's some simple examples to get you started:
it "has successful response" do
response = HTTP.get("www.nrk.no")
expect(response).to be_an_http_gem_response.with(status: :success)
expect(response).to be_an_http_gem_response.with(status: :redirect)
expect(response).to be_an_http_gem_response.with(status: :error)
expect(response).to be_an_http_gem_response.with(status: :ok)
expect(response).to be_an_http_gem_response.with(status: 200)
expect(response).to be_an_http_gem_response.with(status: :not_found)
expect(response).to be_an_http_gem_response.with(status: 404)
end
Supported Ruby Versions
This library aims to support and is tested against
the following Ruby versions:
If something doesn't work on one of these versions, it's a bug.
This library may inadvertently work (or seem to work) on other Ruby versions,
however support will only be provided for the versions listed above.
If you would like this library to support another Ruby version or
implementation, you may volunteer to be a maintainer. Being a maintainer
entails making sure all tests run and pass on that implementation. When
something breaks on your implementation, you will be responsible for providing
patches in a timely fashion. If critical issues for a particular implementation
exist at the time of a major release, support for that Ruby version may be
dropped.
Contributing to http.rb rspec
- Fork http.rb on GitHub
- Make your changes
- Ensure all tests pass (
bundle exec rake
) - Send a pull request
- If we like them we'll merge them
- If we've accepted a patch, feel free to ask for commit access!
Copyright
Copyright © 2011-2023 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker, Simon Toivo Telhaug
See LICENSE.txt for further details.