Skip to content
Browse files

Merge remote branch 'phiggins/minitest' into minitest

  • Loading branch information...
2 parents 4fad36f + 2438099 commit 06456a07f8d740a3c4761a8d600d6f1fe00be486 @bblimke committed Jul 30, 2011
Showing with 63 additions and 0 deletions.
  1. +15 −0 lib/webmock/minitest.rb
  2. +47 −0 spec/minitest_spec.rb
  3. +1 −0 webmock.gemspec
View
15 lib/webmock/minitest.rb
@@ -0,0 +1,15 @@
+require 'minitest/unit'
+require 'webmock'
+
+MiniTest::Unit::TestCase.class_eval do
+ include WebMock::API
+
+ alias_method :teardown_without_webmock, :teardown
+ def teardown_with_webmock
+ teardown_without_webmock
+ WebMock.reset!
+ end
+ alias_method :teardown, :teardown_with_webmock
+end
+
+WebMock::AssertionFailure.error_class = MiniTest::Assertion
View
47 spec/minitest_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+SCRIPT = <<-CODE
+require "rubygems"
+gem "minitest"
+require "minitest/autorun"
+require "webmock/minitest"
+
+class MiniTestWebMockTest < MiniTest::Unit::TestCase
+ def test_that_passes
+ stub_request(:any, "http://example.com")
+
+ r = Net::HTTP.get_response(URI("http://example.com"))
+
+ assert_equal 200, r.code.to_i
+ end
+
+ def test_that_fails
+ r = Net::HTTP.get_response(URI("http://example.com"))
+
+ assert_equal 200, r.code.to_i
+ end
+end
+CODE
+
+describe "MiniTest and WebMock" do
+ def run_test
+ # borrowed from: http://stackoverflow.com/questions/213368
+ ruby = File.join(Config::CONFIG.values_at('bindir', 'ruby_install_name')).
+ sub(/.*\s.*/m, '"\&"')
+
+ # This value makes it so the tests run in the order defined.
+ seed = 9001
+
+ `#{ruby} -Ilib -e '#{SCRIPT}' -- --verbose --seed #{seed}`
+ end
+
+ it "has access to WebMock::API's methods" do
+ re = /^MiniTestWebMockTest#test_that_passes = [0-9]\.[0-9]+ s = \.$/
+ run_test.should match re
+ end
+
+ it "clears WebMock's registry between tests" do
+ re = /test_that_fails\(MiniTestWebMockTest\):\nWebMock::NetConnectNotAllowedError:/m
+ run_test.should match re
+ end
+end
View
1 webmock.gemspec
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'patron', '>= 0.4.9'
s.add_development_dependency 'em-http-request', '>= 0.2.14'
s.add_development_dependency 'curb', '>= 0.7.8'
+ s.add_development_dependency 'minitest', '~> 2.2.2'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 comments on commit 06456a0

Please sign in to comment.
Something went wrong with that request. Please try again.