Ben Marini
unread,Jun 21, 2010, 10:47:55 PM6/21/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to FakeWeb
I have a third party API that I'd like to mock with FakeWeb, but I was
hoping FakeWeb could generate the mocked responses for me the first
time around. What I want would be something like this:
# Setup some type of caching for the request responses, for
example:
CACHE = ActiveSupport::Cache::FileStore.new "test/fixtures/api/"
# If passed a block, yields the method, normalized uri, and
# Net::Http request object
FakeWeb.register_uri(:all, /.*/) do |method, uri, request|
CACHE.fetch(uri) do
# Forces a real request through by temporarily allowing a net
request
FakeWeb.force(request)
end
end
This way I could easily generate the right mock responses for the
requests I make, and then manually tweak them in the "fixture" or
cache file.
Has anyone done something like this already? I'd like to implement
this but want a second opinion since I'm new to this gem.