Sha256: 2dfa73fc6be82d8e1befa96ab4414b0f7070acfdbd5fbab5fe708afe905b9da1

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe VCR::Middleware::Faraday do
  describe '.new' do
    it 'raises an error if no cassette arguments block is provided' do
      expect {
        described_class.new(lambda { |env| })
      }.to raise_error(ArgumentError)
    end
  end

  describe '#call' do
    let(:env_hash) { { :url => 'http://localhost:3000/' } }

    before(:each) do
      VCR::HttpStubbingAdapters::Faraday.ignored_hosts = ['localhost']
    end

    it 'uses a cassette when the app is called' do
      VCR.current_cassette.should be_nil
      app = lambda { |env| VCR.current_cassette.should_not be_nil }
      instance = described_class.new(app) { |c| c.name 'cassette_name' }
      instance.call(env_hash)
      VCR.current_cassette.should be_nil
    end

    it 'sets the cassette name based on the provided block' do
      app = lambda { |env| VCR.current_cassette.name.should == 'rack_cassette' }
      instance = described_class.new(app) { |c| c.name 'rack_cassette' }
      instance.call(env_hash)
    end

    it 'sets the cassette options based on the provided block' do
      app = lambda { |env| VCR.current_cassette.erb.should == { :foo => :bar } }
      instance = described_class.new(app, &lambda do |c|
        c.name    'c'
        c.options :erb => { :foo => :bar }
      end)

      instance.call(env_hash)
    end

    it 'yields the env to the provided block when the block accepts 2 arguments' do
      instance = described_class.new(lambda { |env| }, &lambda do |c, env|
        env.should == env_hash
        c.name    'c'
      end)

      instance.call(env_hash)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vcr-1.11.1 spec/vcr/middleware/faraday_spec.rb
vcr-1.10.3 spec/vcr/middleware/faraday_spec.rb
vcr-1.10.2 spec/vcr/middleware/faraday_spec.rb
vcr-1.10.0 spec/vcr/middleware/faraday_spec.rb
vcr-1.9.0 spec/vcr/middleware/faraday_spec.rb
vcr-1.8.0 spec/vcr/middleware/faraday_spec.rb
vcr-1.7.2 spec/vcr/middleware/faraday_spec.rb
vcr-1.7.1 spec/vcr/middleware/faraday_spec.rb
vcr-1.7.0 spec/vcr/middleware/faraday_spec.rb