[ANN] FakeWeb 1.2.4

9 views
Skip to first unread message

Chris Kampmeier

unread,
Jun 25, 2009, 1:10:38 AM6/25/09
to FakeWeb
Ahoy, a new release! This one's a little bigger than most, so I
figured I'd send out a heads-up.


First, I deprecated some code as a first step on a journey towards a
new API:

1. Calling FakeWeb.register_uri and FakeWeb.registered_uri? without an
HTTP method as the first argument is now deprecated. To match against
any HTTP method (which is how it worked before, if you didn't specify
a method), use :any.

2. Calling FakeWeb.register_uri with the :string or :file options is
now deprecated. Both options have been merged into a unified :body
option, since they supply only the response body (as opposed to
the :response option, which specifies the entire response including
headers). Hopefully that's more clear and easier to remember.

If you use either of the deprecated syntaxes, you'll get a friendly
warning on stdout that tells you how to fix it. So don't fret.


On to the fun stuff, new features!

1. In the past, it was impossible to add response headers when you
just wanted to specify a response body; you had to use the :response
option and provide a full response. Now, you can now specify extra
headers by simply passing additional options, like this:

FakeWeb.register_uri(:get, "http://example.com/hi.txt", :body =>
"Hello!", :content_type => "text/plain")
# adds a 'Content-Type: text/plain' header to your response

2. Experimental regex support for URIs. This has been requested a lot,
and I've been working on it for a while. I say "experimental" because
although the code feels pretty stable, I'd like to see some more
people try it -- sometimes it violates my Principle of Least Surprise
when I'm trying to do something a little complicated, like matching
query params. Anyway, you can do things like this now:

FakeWeb.register_uri(:get, %r{http://example.com/\d+}, :body =>
"number")
# http://example.com/25 => matches
# http://example.com/abc => doesn't match

So, play around with that and let me know what you think.

Oh, and thanks to all the contributors in this release: David Michael,
Jacqui Maher, Tiago Albineli Motta, and Peter Wagene. Enjoy!

Chris

Ben Schwarz

unread,
Jun 27, 2009, 6:43:53 AM6/27/09
to FakeWeb
I'm not too sure what the story is right now Chris but I'm seeing my
`rake spec` process spike to 99% cpu usage when the depreciation
warnings are hit. Adding a :get or :any to the fakeweb register_uri
call still causes it to spike (and hang)

This seems to be when I'm using a regex that simply matches on part of
the url (matching an api method)

Any thoughts of how I could debug this?
>   #http://example.com/abc=> doesn't match

Chris Kampmeier

unread,
Jun 28, 2009, 9:19:39 PM6/28/09
to FakeWeb
On Jun 27, 6:43 am, Ben Schwarz <ben.schw...@gmail.com> wrote:
> I'm not too sure what the story is right now Chris but I'm seeing my
> `rake spec` process spike to 99% cpu usage when the depreciation
> warnings are hit. Adding a :get or :any to the fakeweb register_uri
> call still causes it to spike (and hang)
>
> This seems to be when I'm using a regex that simply matches on part of
> the url (matching an api method)
>
> Any thoughts of how I could debug this?

So you mean it hangs on one of your tests and churns at 99% CPU? Any
idea what's in that test?

I haven't seen anything like that with FakeWeb, but if it's hanging,
the ruby debugger would be a good place to start. You could step
through your code and see where the infinite loop is.

I kinda doubt that the HTTP method stuff would cause any problems,
it's been around since 1.2.0, silently adding an :any to your
FakeWeb.register_uri calls. Regex support is more likely to blame, if
anything :)

Only other thing I can think to ask is: what version/patchlevel of
Ruby are you using?

Chris

Ben Schwarz

unread,
Jun 28, 2009, 9:57:28 PM6/28/09
to FakeWeb
Its the latest patchlevel for standard mac ruby (ruby 1.8.6
(2008-08-11 patchlevel 287) [universal-darwin9.0])

I updated fakeweb to the latest from HEAD and tried to ensure that the
regex would definitely match.
I think its something to do with outgoing requests being turned off
and multiple regexes being returned at once.

Really, I'm not so sure! However, I'm not getting the issue anymore
after a few hours of headbanging. I'll keep an eye out for this again.
To see if I can write a better report :)

Cheers,

B
Reply all
Reply to author
Forward
0 new messages