Sha256: 023b92e3fd95e9a59af82115dfb0118206b4edded62dac151348dc7c8fac8aaf

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 Bytes

Contents

require "vcr"
require "minispec-metadata"

module MinitestVcr
  module Spec

    def self.configure!
      run_before = lambda do |example|
        if metadata[:vcr]
          options = metadata[:vcr].is_a?(Hash) ? metadata[:vcr] : {}
          VCR.insert_cassette StringHelpers.vcr_path(example.class.name, example, spec_name), options
        end
      end

      run_after = lambda do |example|
        ::VCR.eject_cassette if metadata[:vcr]
      end

      ::MiniTest::Spec.before :each, &run_before
      ::MiniTest::Spec.after :each, &run_after
    end

  end # Spec

  module StringHelpers

    def self.vcr_path(example_class_name, example, spec_name)
      prep(example.class.name).push(spec_name).join("/")
    end

    protected

    def self.prep string
      string.split("::").map {|e| e.sub(/[^\w]*$/, "")}.reject(&:empty?) - ["vcr"]
    end

  end
end # MinitestVcr

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minitest-vcr-1.2.1 lib/minitest-vcr/spec.rb