Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store Multiple Requests for Inspection #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paulbellamy
Copy link

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

  * Allows you to inspect more than just the last request
  * Fully backward compatible
  * Provides FakeWeb.clear_requests which clears the log of received requests
@openfirmware
Copy link

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.

@gregory-m
Copy link

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

@jshou
Copy link

jshou commented Jan 24, 2012

+1!

@pat
Copy link

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
Copy link

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants