0.0
No commit activity in last 3 years
No release in over 3 years
Faraday Cage allows you to use Faraday for making requests to your REST APIs in integration testing, minus the boilerplate code and crufty parsing and encoding of requests and responses.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 1.0, >= 0.8
>= 1.0
>= 0.5.4
 Project Readme

Faraday Cage

Description

Faraday Cage allows you to use Faraday for making requests to your APIs in integration testing, minus the boilerplate code and repeated parsing and encoding of requests and responses.

Installation

Add this line to your application's Gemfile:

gem 'faraday_cage'

And then execute:

$ bundle

Or install it yourself as:

$ gem install faraday_cage

Usage with RSpec

Load RSpec support by adding the following to your spec_helper.rb:

require 'faraday_cage/rspec'

Configure the middleware you would like to use (see Faraday and faraday_middleware for more information):

FaradayCage.middleware do |conn|
  conn.request  :json
  conn.response :mashify
  conn.response :json, content_type: /\bjson$/

  conn.options[:preserve_raw] = true
end

You will now be able to test your app like so:

describe 'creating a gist' do

  before do
    header :accept, 'application/vnd.github.v3'
    basic_auth 'username', 'password'
  end

  let(:gist) do
    {
      description: 'This is my gist, there are many like it but this one is mine.',
      public: true,
      files: [
        'file1.txt' => {
          content: 'cool beans'
        }
      ]
    }
  end

  subject { post 'gists', gist }

  its(:status) { should be_created }

  it 'references the location of the created gist' do
    body[:url].should =~ %r{^https://api.github.com/gists/[a-f0-9]+$}
  end
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request