lib/minitest-vcr/spec.rb in minitest-vcr-0.0.2 vs lib/minitest-vcr/spec.rb in minitest-vcr-0.0.3
- old
+ new
@@ -1,32 +1,18 @@
require "vcr"
require "minispec-metadata"
+require "extensions/string"
module MinitestVcr
module Spec
def self.configure!
run_before = lambda do |example|
- if metadata[:vcr]
- example.class.name.scan(/^(.*?)::[abc]/) do |name|
- @class_name = name.first
- end
-
- if @class_name.nil?
- test_info = example.class.name.split("::").map {|e| e.sub(/[^\w]*$/, "")}.reject(&:empty?) - ["vcr"]
- @class_name = ""
- else
- test_info = example.class.name.gsub(@class_name, "").split("::").map {|e| e.sub(/[^\w]*$/, "")}.reject(&:empty?) - ["vcr"]
- end
-
- VCR.insert_cassette @class_name + "/" + test_info.join("/") + "/#{spec_name}"
- end
+ VCR.insert_cassette example.class.name.vcr_path(example, spec_name) if metadata[:vcr]
end
run_after = lambda do |example|
- if metadata[:vcr]
- ::VCR.eject_cassette
- end
+ ::VCR.eject_cassette if metadata[:vcr]
end
::MiniTest::Spec.before :each, &run_before
::MiniTest::Spec.after :each, &run_after
end