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

Already on GitHub? Sign in to your account

Store Multiple Requests for Inspection #27

wants to merge 2 commits into


5 participants

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 added some commits May 5, 2011

@paulbellamy paulbellamy Added .rvmrc to gitignore 62063fb
@paulbellamy paulbellamy Adding multiple request storage
  * Allows you to inspect more than just the last request
  * Fully backward compatible
  * Provides FakeWeb.clear_requests which clears the log of received requests

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.

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

jshou commented Jan 24, 2012


pat commented Jan 25, 2012

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.

jshou commented May 12, 2012

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment