Sha256: 8d9330b4ddc7a38784548bc08757ecfd56fe2182172a2cb8bcb7c2ac6d10eb4f

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

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

2 entries across 2 versions & 1 rubygems

Version Path
vcr-2.0.0.beta2 lib/vcr/test_frameworks/rspec.rb
vcr-2.0.0.beta1 lib/vcr/test_frameworks/rspec.rb