Sha256: 9904387761479556527ed4dddebe5655e348bc30536483add8448edc2dac486e

Contents?: true

Size: 908 Bytes

Versions: 11

Compression:

Stored size: 908 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

11 entries across 11 versions & 1 rubygems

Version Path
vcr-1.11.3 lib/vcr/test_frameworks/rspec.rb
vcr-1.11.2 lib/vcr/test_frameworks/rspec.rb
vcr-1.11.1 lib/vcr/test_frameworks/rspec.rb
vcr-1.10.3 lib/vcr/test_frameworks/rspec.rb
vcr-1.10.2 lib/vcr/test_frameworks/rspec.rb
vcr-1.10.0 lib/vcr/test_frameworks/rspec.rb
vcr-1.9.0 lib/vcr/test_frameworks/rspec.rb
vcr-1.8.0 lib/vcr/test_frameworks/rspec.rb
vcr-1.7.2 lib/vcr/test_frameworks/rspec.rb
vcr-1.7.1 lib/vcr/test_frameworks/rspec.rb
vcr-1.7.0 lib/vcr/test_frameworks/rspec.rb