Sha256: 3f32b56a9397b3d31399ed2d9321fdd024da589cbe428a0770b3d4450cb19b86

Contents?: true

Size: 923 Bytes

Versions: 9

Compression:

Stored size: 923 Bytes

Contents

require 'vcr'

module VCR
  module RSpec
    module Macros
      def use_vcr_cassette(*args)
        options = args.last.is_a?(Hash) ? args.pop : {}
        name    = args.first || infer_cassette_name

        before(:each) do
          VCR.insert_cassette(name, options)
        end

        after(:each) do
          VCR.eject_cassette
        end
      end

      private

      def infer_cassette_name
        # RSpec 1 exposes #description_parts; use that if its available
        return description_parts.join("/") if respond_to?(:description_parts)

        # Otherwise use RSpec 2 metadata...
        group_descriptions = []
        klass = self

        while klass.respond_to?(:metadata) && klass.metadata
          group_descriptions << klass.metadata[:example_group][:description]
          klass = klass.superclass
        end

        group_descriptions.compact.reverse.join('/')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vcr-1.6.0 lib/vcr/rspec.rb
vcr-1.5.1 lib/vcr/rspec.rb
vcr-1.5.0 lib/vcr/rspec.rb
vcr-1.4.0 lib/vcr/rspec.rb
vcr-1.3.3 lib/vcr/rspec.rb
vcr-1.3.2 lib/vcr/rspec.rb
vcr-1.3.1 lib/vcr/rspec.rb
vcr-1.3.0 lib/vcr/rspec.rb
vcr-1.2.0 lib/vcr/rspec.rb