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