fakeweb icon indicating copy to clipboard operation
fakeweb copied to clipboard

Store Multiple Requests for Inspection

Open paulbellamy opened this issue 13 years ago • 5 comments

What I did:

  • Refactored @last_request into an array called @requests
  • FakeWeb.last_request=(request) now appends to @requests
  • FakeWeb.last_request returns @requests.last (maintains backwards compatibility)
  • FakeWeb.clear_requests sets @requests to nil (clearing received requests)
  • FakeWeb.requests returns @requests for inspection

Use Case: When code makes multiple requests and you care about a request other than the last one made.

Usage: - To check the last request made by a test I do FakeWeb.last_request (backwards compatible)

  • To check the first request for a test I do FakeWeb.requests.first
  • To check the second-last request I do FakeWeb.requests[-2]
  • Etc...
  • After each test (where I was doing FakeWeb.clean_registry), I add a call to FakeWeb.clear_requests

paulbellamy avatar May 05 '11 15:05 paulbellamy

Interesting we both came up with similar solutions: https://github.com/openfirmware/fakeweb/tree/multiple_recent_requests

I like your tests better than mine, though.

openfirmware avatar May 16 '11 19:05 openfirmware

+1 for this one. I also sometimes need this functionality in my specs.

gregory-m avatar Sep 11 '11 11:09 gregory-m

+1!

jshou avatar Jan 24 '12 23:01 jshou

Excuse me pimping something of my own, but I wrote a gem some time ago that lets you set expectations on which requests have been made: https://github.com/freelancing-god/fakeweb-matcher

Granted, it's built for RSpec, but could likely also be used in TestUnit.

pat avatar Jan 25 '12 05:01 pat

Any updates on this?

jshou avatar May 12 '12 00:05 jshou