Skip to content

Conversation

@ryansch
Copy link

@ryansch ryansch commented Dec 4, 2010

I've got preliminary support for the following syntax:

FakeWeb.register_uri(:post, "#{Utility.test_domain}/subscriptions.xml") do |request_args|
    make_subscription request_args
end

The block is executed each time a request comes in. This allows a FakeWeb client to return responses based on the request body (or anything else). The request_args looks like this:

{:request=>#<Net::HTTP::Post POST>,
 :uri=>
  "https://<host redacted>/subscriptions.xml",
 :method=>:post}

The block needs to return a hash (or array of hashes) that looks like the parameters that are missing from request_uri like so:
{:status => 200, :body => "hi"}

Any of the options you can normally pass to request_uri after the http method and url are valid in the block return value.

This is a work in progress and has no tests yet. I'm looking for feedback at this point.

@ryansch
Copy link
Author

ryansch commented Aug 23, 2011

An update.

This code has been working great but sham_rack is really a better tool for this use case. I much prefer the sinatra syntax to what I've written here. That said, I'll keep this pull request open in case someone finds it useful. I won't be adding tests or refining the code at all.

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.

1 participant