Skip to content

Commit

Permalink
Fix bug with overriding #setup/#teardown on Minitest::Spec
Browse files Browse the repository at this point in the history
If any of other test helping library calls ::MiniTest::Spec.before or
::MiniTest::Spec.after, the last one called wins. That should not be the case.
It makes for really had to track down bugs

Fixes mfpiccolo#24
  • Loading branch information
Aryk committed Jul 3, 2017
1 parent 4334bb7 commit debb44e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
17 changes: 9 additions & 8 deletions lib/minitest-vcr/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

module MinitestVcr
module Spec

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

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

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

def self.configure!
::MiniTest::Spec.send(:include, SetupAndTeardown)
end
end # Spec

module StringHelpers
Expand Down

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

8 changes: 2 additions & 6 deletions test/minitest-vcr/spec_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@

describe "#configure!", :vcr do

before do
::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
it "should include setup and teardown module into Minitest::Spec" do
MinitestVcr::Spec.configure!
Minitest::Spec.included_modules.must_include(MinitestVcr::Spec::SetupAndTeardown)
end
end
end

0 comments on commit debb44e

Please sign in to comment.