Skip to content

Commit

Permalink
RequestRegistry to_s reports all executed requests together with the …
Browse files Browse the repository at this point in the history
…number of executions
  • Loading branch information
bblimke committed Nov 10, 2010
1 parent a200077 commit b49cae2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/webmock/request_registry.rb
Expand Up @@ -19,5 +19,17 @@ def times_executed(request_pattern)
}.inject(0) {|sum, (_, times_executed)| sum + times_executed }
end

def to_s
if requested_signatures.hash.empty?
"No requests were made."
else
text = ""
self.requested_signatures.hash.each do |request_signature, times_executed|
text << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n"
end
text
end
end

end
end
18 changes: 18 additions & 0 deletions spec/request_registry_spec.rb
Expand Up @@ -54,4 +54,22 @@
end
end

describe "to_s" do
it "should output string with all executed requests and numbers of executions" do
[
WebMock::RequestSignature.new(:get, "www.example.com"),
WebMock::RequestSignature.new(:get, "www.example.com"),
WebMock::RequestSignature.new(:put, "www.example.org"),
].each do |s|
WebMock::RequestRegistry.instance.requested_signatures.put(s)
end
WebMock::RequestRegistry.instance.to_s.should ==
"PUT http://www.example.org/ was made 1 time\nGET http://www.example.com/ was made 2 times\n"
end

it "should output info if no requests were executed" do
WebMock::RequestRegistry.instance.to_s.should == "No requests were made."
end
end

end

0 comments on commit b49cae2

Please sign in to comment.