Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix minitest assertions count #215

Merged
merged 1 commit into from Feb 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/webmock/minitest.rb
Expand Up @@ -10,6 +10,15 @@ def teardown_with_webmock
WebMock.reset!
end
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

WebMock::AssertionFailure.error_class = MiniTest::Assertion
1 change: 1 addition & 0 deletions minitest/test_webmock.rb
Expand Up @@ -3,4 +3,5 @@

class MiniTestWebMock < MiniTest::Unit::TestCase
include SharedTest

end
11 changes: 11 additions & 0 deletions minitest/webmock_spec.rb
Expand Up @@ -8,6 +8,17 @@
@stub_https = stub_http_request(:any, "https://www.example.com")
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
lambda { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError)
end
Expand Down
2 changes: 1 addition & 1 deletion test/shared_test.rb
Expand Up @@ -73,4 +73,4 @@ def test_verification_that_non_expected_stub_didnt_occur
assert_not_requested(@stub_http)
end
end
end
end