Skip to content

Commit

Permalink
assert_requested and assert_not_requested raise an error if a stub ob…
Browse files Browse the repository at this point in the history
…ject is provided together with a block.
  • Loading branch information
bblimke committed Feb 28, 2013
1 parent 70cd96f commit 6a7804b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## Master

* `assert_requested` and `assert_not_requested` raise an error if a stub object is provided together with a block.

## 1.9.3

* Fixed issue with unavailable constant Mutex in Ruby < 1.9
Expand Down
8 changes: 6 additions & 2 deletions lib/webmock/api.rb
Expand Up @@ -21,15 +21,19 @@ class << self
def assert_requested(*args, &block)
if not args[0].is_a?(WebMock::RequestStub)
args = convert_uri_method_and_options_to_request_and_options(*args, &block)
elsif block
raise ArgumentError, "assert_requested with a stub object, doesn't accept blocks"
end
assert_request_requested(*args, &block)
assert_request_requested(*args)
end

def assert_not_requested(*args, &block)
if not args[0].is_a?(WebMock::RequestStub)
args = convert_uri_method_and_options_to_request_and_options(*args, &block)
elsif block
raise ArgumentError, "assert_not_requested with a stub object, doesn't accept blocks"
end
assert_request_not_requested(*args, &block)
assert_request_not_requested(*args)
end

def hash_including(expected)
Expand Down
12 changes: 12 additions & 0 deletions test/shared_test.rb
Expand Up @@ -9,6 +9,18 @@ def setup
@stub_https = stub_http_request(:any, "https://www.example.com")
end

def test_assert_requested_with_stub_and_block_raises_error
assert_raise ArgumentError do
assert_requested(@stub_http) {}
end
end

def test_assert_not_requested_with_stub_and_block_raises_error
assert_raise ArgumentError do
assert_not_requested(@stub_http) {}
end
end

def test_error_on_non_stubbed_request
default_ruby_headers = (RUBY_VERSION >= "1.9.1") ? "{'Accept'=>'*/*', 'User-Agent'=>'Ruby'}" : "{'Accept'=>'*/*'}"
assert_raise_with_message(WebMock::NetConnectNotAllowedError, %r{Real HTTP connections are disabled. Unregistered request: GET http://www.example.net/ with headers}) do
Expand Down

0 comments on commit 6a7804b

Please sign in to comment.