lib/minitest-vcr/spec.rb in minitest-vcr-0.1.1 vs lib/minitest-vcr/spec.rb in minitest-vcr-1.0.0

- old
+ new

@@ -1,25 +1,48 @@ require "vcr" require "minispec-metadata" -require "extensions/string" -require "database_cleaner" module MinitestVcr module Spec def self.configure! run_before = lambda do |example| - DatabaseCleaner.start rescue DatabaseCleaner::NoORMDetected - VCR.insert_cassette example.class.name.vcr_path(example, spec_name) if metadata[:vcr] + 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] - DatabaseCleaner.clean rescue DatabaseCleaner::NoORMDetected 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) + example_class_name.scan(/^(.*?)::[#a-z]/) do |class_names| + class_name = class_names.flatten.first + + if class_name.nil? + @path = prep example.class.name + else + @path = prep(example.class.name.gsub(class_name, "")).unshift(class_name) + end + end + + @path.push(spec_name).join("/") unless @path.nil? + end + + protected + + def self.prep string + string.split("::").map {|e| e.sub(/[^\w]*$/, "")}.reject(&:empty?) - ["vcr"] + end + + end end # MinitestVcr