Sha256: 4723868a44033c51a80593f839fee75078e592307e3f468994cfc44c2dfd4a86

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'
require 'vcr/library_hooks/faraday'

describe "Faraday hook" do
  it 'inserts the VCR middleware just before the adapter' do
    conn = Faraday.new(:url => 'http://sushi.com') do |builder|
      builder.request  :url_encoded
      builder.response :logger
      builder.adapter  :net_http
    end

    conn.builder.lock!
    conn.builder.handlers.last(2).map(&:klass).should eq([
      VCR::Middleware::Faraday,
      Faraday::Adapter::NetHttp
    ])
  end

  it 'handles the case where no adapter is declared' do
    conn = Faraday.new

    conn.builder.lock!
    conn.builder.handlers.last(2).map(&:klass).should eq([
      VCR::Middleware::Faraday,
      Faraday::Adapter::NetHttp
    ])
  end

  it 'does nothing if the VCR middleware has already been included' do
    conn = Faraday.new(:url => 'http://sushi.com') do |builder|
      builder.use VCR::Middleware::Faraday
      builder.use Faraday::Response::Logger
      builder.use Faraday::Adapter::NetHttp
    end

    conn.builder.lock!
    conn.builder.handlers.map(&:klass).should eq([
      VCR::Middleware::Faraday,
      Faraday::Response::Logger,
      Faraday::Adapter::NetHttp
    ])
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vcr-2.1.1 spec/vcr/library_hooks/faraday_spec.rb
vcr-2.1.0 spec/vcr/library_hooks/faraday_spec.rb
vcr-2.0.1 spec/vcr/library_hooks/faraday_spec.rb
vcr-2.0.0 spec/vcr/library_hooks/faraday_spec.rb