Skip to content

Commit

Permalink
Refactor spec logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mfpiccolo committed Jan 15, 2014
1 parent ebd2228 commit 6f10a73
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/minitest-vcr/spec.rb
@@ -1,24 +1,25 @@
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"]
example.class.name.scan(/^(.*?)::[abc]/) do |class_names|
class_name = class_names.first

if class_name.nil?
@path = example.class.name.prep
else
@path = example.class.name.gsub(class_name, "").prep.unshift(class_name)
end
end

VCR.insert_cassette @class_name + "/" + test_info.join("/") + "/#{spec_name}"
VCR.insert_cassette @path.push(spec_name).join("/") unless @path.nil?
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/minitest-vcr/spec_test.rb
Expand Up @@ -41,8 +41,8 @@
describe "#configure!", :vcr do

before do
::MiniTest::Spec.expects(:before).with(:each).returns(:true)
::MiniTest::Spec.expects(:after).with(:each).returns(true)
::MiniTest::Spec.expects(:before).with(:each)
::MiniTest::Spec.expects(:after).with(:each)
end

it "should call before and after with proper args and block" do
Expand Down

0 comments on commit 6f10a73

Please sign in to comment.