Every repository with this icon (
Every repository with this icon (
| Description: | A test helper for faking responses to web requests edit |
-
Tests are failing on 1.9.2-preview1. Looks related to changes in Net::HTTP, possibly the
#read_nonblockmethod.Comments
-
I like to have a failsafe setup where net_connects are disallowed by default.
I've implemented a method for specifying some URIs which are whitelisted.Please let me know if I need more test coverage, or if the implementation could be more obvious.
The branch "passthrough" is on my fork.
halorgium@15f5eb2Comments
Howdy Tim, cool change (nice tests!).
I'm wondering, what's your use case for this? Are you hitting an HTTP service that you consider to be part of the System Under Test, like a CouchDB instance or something?
Thanks,
Chris
CodeMonkeySteve
Sat Oct 17 11:18:28 -0700 2009
| link
BTW, I'm also looking for the same feature (thanks halorgium). In my case I am hitting a CouchDB instance, although I could see user other local services well.
-
The soap4r gem currently uses httpclient gem which is not currently disabled when used with fakeweb (allow_net_connect = false).
It looks as though some work has been done at http://github.com/dkubb/fakeweb/commit/430bdc3cbed18d38f8a2391053c26e9e2262d671 although it is now a bit out of date.
Comments
So, I put together my own patch which adds this support - however - it's certainly not for mainline use as it is specific to httpclient + soap4r at the moment: http://gist.github.com/206226
However, it raised the interesting idea of abstracting the generated Net::HTTPResponse object to fit other libraries. In this case, I had to extend the response to carry
statusandcontentmethods. It may be more useful to have a custom response object come back throughFakeWeb.response_for, in most cases the current Net::HTTP-like object, but for httpclient, for instance, a slightly modified version. If that were available, I wouldn't have had to monkey with Net::HTTPHeader and HTTPClient in this patch.Just a thought.
Note to self, httpclient is now on github. http://github.com/nahi/httpclient
-
Right now, the query params of the incoming request are sorted by key before we try to match against all the registered Regexps and URI objects. This works fine for URIs, because we can sort those query params too, so the user doesn't even know.
For Regexps, though, it seems impossible to figure out what part of the Regexp represents the query params and sort it; so the user has to be aware that their Regexp must be written to match against sorted params. That can be kind of hard sometimes. For example, a registration might look something like:
/example\.com\?[z\d]{2}=1&(opt1=a|opt2=b)$/To match this URI:
http://example.com?9z=1&opt2=bBut also this URI:
http://example.com?zz=1&opt1=aSo you can see that if we sorted the second URI's params by key, it wouldn't match the Regexp. Instead, the user would have to register a Regexp that matches either order (or do two
register_uricalls), which is pretty ugly.We tried getting around this by calculating all the possible orders of the params and matching them, but that's O(n!) and therefore intractable for even pretty reasonable query params counts.
So the idea is that we could add a new API entirely, and get the query params out of the Regexp. Maybe an additional argument to
register_uriwith a hash of params that must in the request?(Forked from issue #5.)
Comments
-
Final release in the 1.1.x series that prints warnings about the gem rename
0 comments Created 23 days ago by chriskAccording to the stats on rubyforge and gemcutter, it looks like a few users are still installing the old
FakeWebversions of the gem.We could probably ask to have them removed outright, since the pre-1.2.0 gem versions are still available as "fakeweb" gems.
I think a nicer solution would be to do a final release in the 1.1.x series that uses RubyGems's post-install hook to print out a note about the
FakeWeb->fakewebchange. Maybe add a warning when that version is required, too. It might be annoying, but the exact same versions of the gems exist under thefakewebname, so switching should be pretty easy for anyone still using the old gems.Comments
-
There are a lot of situations when we need to stub FTP calls. It would be awesome to implement such functionality for that gem. I could help you with that.
Comments












1.9.2's Net::HTTP uses
#read_nonblocknow thanks to a patch from tenderlove. It was applied in r20443.So I'm seeing two things that need fixing:
the "FakeFakeWeb" that tests for requests making it down to the socket level expects a call to
#sysreadinstead of#read_nonblock. So that's a false negative, just need to adjust our tests.StringIO doesn't have the
#read_nonblockmethod defined in 1.9.2-preview1, which prevents us from using it interchangeably with IO objects. This was fixed in r25517, which should be part of the next release. I could extend the StringIOs we instantiate to define that method, but I think it'd be better to just skip 1.9.2-preview1 compatibility and confirm that everything works with the next 1.9.2 release.Also, URI.escape prints a warning now: "URI.escape is obsolete". So we should get rid of that. Here's what Rails did: rails/rails@a2de13e
URI.parse is also deprecated. yikes. rails/rails@76b2d3e
Fixed the tests for
#read_nonblockin cb8463d. Added a compatibility wrapper forURI.escapein 917bd1c.