Question

So I'm testing the individual parts of my crawler and now I've hit a stump: mocking the actual requests.

I don't want to make a request every time I run a spec.

Anyone ever tried starting a webrick server in the test helper?

Something like

myserver = SomeServerLib.start('localhost', some_port)
myserver.serve_directory(a_directory_with_some_html_files)

Thanks!

Was it helpful?

Solution

You can mock the HTTP request and use expectations. See Webmock project.

OTHER TIPS

You can also use FakeWeb, which lets you provide canned HTTP responses during tests.

http://fakeweb.rubyforge.org/

(As a side note, you probably should look into alternatives if you're using Net::HTTP. It's very slow. Check out em-http-request )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top