What have you found for these years?

2010-03-17

fakeweb for testing Net::HTTP

(from my email with some editing)
2010-03-17 18:59
fakeweb for testing Net::HTTP

I am tired of slow testing,
it runs 2 minutes on my computer.

~/p/c/travelballoon *dev> time rake test
[snipped]
123.85 real 39.53 user 5.86 sys

And I think it's better to stub or mock any external request...
I tried to use RR to mock them, but later thought it's
very tough to mock them, because `attachment_fu'
(who didn't respond to my patch for Ruby 1.9.1)
is an external library, and `aws-s3' is also an external library,
which I have almost no knowledge on them. (never used)

I think there must have some libraries lying around
mocking, stubbing, faking Net::HTTP,
because it should be a common issue...

So I googled a bit and found fakeweb.

I have given it a try, and updated a single test method
to use it faking out Net::HTTP. Now it saves me 15s!!!
Only fake out 3 HTTP request! S3 is somehow so slow...
Or is it just uploading a very large image?

~/p/c/travelballoon *dev-fakeweb> time rake test
107.04 real 38.92 user 5.86 sys

I have written some helper for it,
so the usage should look like this:

p = Photo.new(blah)
fakeweb_register(:put, p)

p.save # this would call fakeweb

The faked out URL would be:
%r{#{base}/#{bucket}/#{table}/#{id}/#{name}}

It's too hard to do perfect match because of the design
of `attachment_fu', etc, so I end up just write regexp...

I hope running time could be
reduced to lesser than 30 seconds...

Hope this help speed up development process,
and run `gem install fakeweb` to install it.
cheers,

2 retries:

Bartosz Blimke said...

Take a look at WebMock http://github.com/bblimke/webmock

Lin Jen-Shin (aka godfat 真常) said...

Thanks!! Watched in github.
I'll try it later.

Post a Comment

All texts are licensed under CC Attribution 3.0