ActiveResource, FakeWeb & Regex Mojo (authenticated edition)
Have a web service which needs requires authentication, but you’re testing a completely different part of the application? Again, FakeWeb & Regex help you out here. If you’re testing a model extended from ActiveResource by using FakeWeb, the url will look something like this:
To mock the request, use a regular expression like so:
FakeWeb.register_uri :get, %r|http:(.*)example.com/someService|, :body => 'foo'
Now you don’t have to worry about how you are authenticated. Of course you could use a more advanced regular expression, but we’re not testing that ActiveResource knows how to authenticate with a source, right?