Skip to content

Commit

Permalink
Minitest < 5.0 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblimke committed Jun 26, 2013
1 parent 0af60fd commit b2e7686
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/webmock/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
require 'minitest/test'
begin
require 'minitest/test'
test_class= MiniTest::Test
assertions = "assertions"
rescue LoadError
require "minitest/unit"
test_class = MiniTest::Unit::TestCase
assertions = "_assertions"
end

require 'webmock'

MiniTest::Test.class_eval do
test_class.class_eval do
include WebMock::API

alias_method :teardown_without_webmock, :teardown
Expand All @@ -14,7 +23,7 @@ def teardown_with_webmock
[:assert_request_requested, :assert_request_not_requested].each do |name|
alias_method :"#{name}_without_assertions_count", name
define_method :"#{name}_with_assertions_count" do |*args|
self.assertions += 1
self.send("#{assertions}=", self.send("#{assertions}") + 1)
send :"#{name}_without_assertions_count", *args
end
alias_method name, :"#{name}_with_assertions_count"
Expand Down
4 changes: 3 additions & 1 deletion minitest/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
require 'minitest/autorun'
require 'webmock/minitest'

class MiniTest::Test
test_class = defined?(MiniTest::Test) ? MiniTest::Test : MiniTest::Unit::TestCase

test_class.class_eval do

def assert_raise(*exp, &block)
assert_raises(*exp, &block)
Expand Down
5 changes: 4 additions & 1 deletion minitest/test_webmock.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../test/shared_test')

class MiniTestWebMock < MiniTest::Test
test_class = defined?(MiniTest::Test) ? MiniTest::Test : MiniTest::Unit::TestCase


class MiniTestWebMock < test_class
include SharedTest
end

0 comments on commit b2e7686

Please sign in to comment.