chrisk / fakeweb

Ruby test helper for injecting fake responses to web requests
MIT License
1.09k stars 134 forks source link

Different Responses to the same URI based on the passed data #41

Open mhaseebkhan opened 11 years ago

mhaseebkhan commented 11 years ago

I am working on a project using fakeweb. Found it to be useful. :)

I have a scenario in which I need to return different responses based on the data passed in the request on the same URI. Example below:

FakeWeb.register_uri(:post,
                           %r{http:\/\/api.flickr.com\/services\/rest\/},
                           parameters: {method: 'flickr.reflection.getMethods', format: 'json', nojsoncallback: "1"},
                           body: "First Content")

# Should return First Content

FakeWeb.register_uri(:post,
                           %r{http:\/\/api.flickr.com\/services\/rest\/},
                           parameters: {method: 'flickr.photos.getRecent', format: 'json', nojsoncallback: "1"},
                           body: "Second Content")

# Should return Second Content

In the case above, the URI is the same, however, the values of the parameters are different.

How this can be achieved?

drunkonsound commented 10 years ago

It doesn't look like this functionality is currently present, I also need this feature and haven't yet found a solution.

ajay-vmware commented 9 years ago

They support rotating responses but that too doesn't seem to work. It always responds with first registered response.