Permalink
Browse files

Merge pull request #215 from mokevnin/fix-minitest-assertions-count

fix minitest assertions count
  • Loading branch information...
bblimke committed Feb 17, 2013
2 parents 9460638 + 66e8990 commit 88ad2e3a5bd1d15fd82e2d3a5314e464fdd356e6
Showing with 22 additions and 1 deletion.
  1. +9 −0 lib/webmock/minitest.rb
  2. +1 −0 minitest/test_webmock.rb
  3. +11 −0 minitest/webmock_spec.rb
  4. +1 −1 test/shared_test.rb
View
@@ -10,6 +10,15 @@ def teardown_with_webmock
WebMock.reset! WebMock.reset!
end end
alias_method :teardown, :teardown_with_webmock alias_method :teardown, :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
send :"#{name}_without_assertions_count", *args
end
alias_method name, :"#{name}_with_assertions_count"
end
end end
WebMock::AssertionFailure.error_class = MiniTest::Assertion WebMock::AssertionFailure.error_class = MiniTest::Assertion
View
@@ -3,4 +3,5 @@
class MiniTestWebMock < MiniTest::Unit::TestCase class MiniTestWebMock < MiniTest::Unit::TestCase
include SharedTest include SharedTest
end end
View
@@ -8,6 +8,17 @@
@stub_https = stub_http_request(:any, "https://www.example.com") @stub_https = stub_http_request(:any, "https://www.example.com")
end end
it "should update assertions count" do
assert_equal 0, _assertions
http_request(:get, "http://www.example.com/")
assert_requested(@stub_http)
assert_equal 2, _assertions
assert_not_requested(:post, "http://www.example.com")
assert_equal 4, _assertions
end
it "should raise error on non stubbed request" do it "should raise error on non stubbed request" do
lambda { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError) lambda { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError)
end end
View
@@ -73,4 +73,4 @@ def test_verification_that_non_expected_stub_didnt_occur
assert_not_requested(@stub_http) assert_not_requested(@stub_http)
end end
end end
end end

0 comments on commit 88ad2e3

Please sign in to comment.