lib/minitest-vcr/spec.rb in minitest-vcr-1.2.1 vs lib/minitest-vcr/spec.rb in minitest-vcr-1.2.2
- old
+ new
@@ -6,11 +6,11 @@
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
+ VCR.insert_cassette StringHelpers.vcr_path(example), options
end
end
run_after = lambda do |example|
::VCR.eject_cassette if metadata[:vcr]
@@ -22,17 +22,36 @@
end # Spec
module StringHelpers
- def self.vcr_path(example_class_name, example, spec_name)
- prep(example.class.name).push(spec_name).join("/")
+ def self.vcr_path(example)
+ description_stack(example).push(extract_example_description(example)).join("/")
end
protected
- def self.prep string
- string.split("::").map {|e| e.sub(/[^\w]*$/, "")}.reject(&:empty?) - ["vcr"]
+ def self.description_stack(example)
+ frame = example.class
+ stack = []
+
+ while frame != Minitest::Spec do
+ stack.unshift frame.desc.to_s
+ frame = frame.superclass
+ end
+
+ return stack
+ end
+
+ # Minitest::Spec takes the example description and writes
+ # a test_NNNN_ in front of it, and doesn't actually keep
+ # the original anywhere. Okay, we'll take it out.
+ def self.extract_example_description(example)
+ if (example.name =~ /\Atest_\d{4}_(.*)\z/)
+ return $1
+ else
+ return example.name
+ end
end
end
end # MinitestVcr