Skip to content

Commit

Permalink
Added WebMock.print_executed_requests method which can be useful to f…
Browse files Browse the repository at this point in the history
…ind out what requests were made until given point.
  • Loading branch information
bblimke committed Nov 11, 2010
1 parent 06d6b39 commit 72cd989
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

* The expectation failure message now contains a list of made requests. Thanks to Martyn Loughran for suggesting this feature.

* Added `WebMock.print_executed_requests` method which can be useful to find out what requests were made until given point.

* Fixed issue with stubbing requests with request body declared as a hash, when json was not required. Thanks to Erik Michaels-Ober for reporting the issue.

* Fixed issue with em-http-request adapter which didn't work when :query option value was as a string, not a hash. Thanks to Chee Yeo for reporting the issue.
Expand Down
13 changes: 7 additions & 6 deletions lib/webmock/request_execution_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def does_not_match?
def failure_message
expected_times_executed = @expected_times_executed || 1
text = %Q(The request #{request_pattern.to_s} was expected to execute #{times(expected_times_executed)} but it executed #{times(times_executed)})
text << executed_requests
text << executed_requests_message
text
end

Expand All @@ -38,18 +38,19 @@ def negative_failure_message
else
%Q(The request #{request_pattern.to_s} was expected to execute 0 times but it executed #{times(times_executed)})
end
text << executed_requests
text << executed_requests_message
text
end

def self.executed_requests_message
"\n\nThe following requests were made:\n\n#{RequestRegistry.instance.to_s}\n" + "="*60
end

private

def times(times)
"#{times} time#{ (times == 1) ? '' : 's'}"
end

def executed_requests
"\n\nThe following requests were made:\n\n#{RequestRegistry.instance.to_s}\n" + "="*60
end

end
end
4 changes: 4 additions & 0 deletions lib/webmock/webmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def self.registered_request?(request_signature)
WebMock::StubRegistry.instance.registered_request?(request_signature)
end

def self.print_executed_requests
puts WebMock::RequestExecutionVerifier.executed_requests_message
end

%w(
allow_net_connect!
disable_net_connect!
Expand Down

0 comments on commit 72cd989

Please sign in to comment.