© Copyright 2010-2011 C42 Engineering. All Rights Reserved.
RSpec HTTP is a RSpec extension library that adds support for writing specs that cover HTTP based APIs (or more popularly, RESTful APIs).
To use this library, first add the rspec-http gem to your Gemfile like so:
gem 'rspec-http', '~> 0.9'
Then add the following line to your spec_helper.rb:
require 'rspec/http'
This will make matchers such as the ones listed below available to you in your specs.
response.should be_http_ok response.should be_http_created response.should be_http_unprocessable_entity response.should be_http_im_a_teapot response.should have_header('Content-Type') response.should have_header('Content-Type' => 'application/json') response.should have_header('Content-Type' => /json/)
If you’re using Rails (and implicitly, rspec-rails), the same http code matchers will also be available in your controller specs without the http
namespace. In other words, in your controller specs you can do:
response.should be_ok response.should be_created response.should be_unprocessable_entity response.should be_im_a_teapot