[rspec-users] How to mock out a WEBrick::HTTPServer?

Ian Vaughan ianrvaughan at gmail.com
Sun Jan 15 09:48:58 EST 2012

partial code : http://pastie.org/3186140

I want to test a HTTP server, I'm using lower level stuff so I can
understand whats going on, then I might move onto FakeWeb/WebMock/etc

Its a reverse proxy, so it doesn't generate the page content.

I want to test
a/ methods in the class in isolation
b/ test that if a HTTP request sent in generates a HTTP request out
(suppose should be just a method to test)
c/ and that the HTTP response given to the proxy with body is passed
back from the client.

Problems I'm running into
1. rpsec creates new instants of my proxy each test, such that multi
HTTP servers are running (see rspec implicate-subject)
1.1 This is due to my #initialise creating the HTTPServer, so is that
bad code in the init?
1.2 I did that so that starting is neater "Proxy.new.start"

2. I want to mock out the WEBrick::HTTPServer!
2.1 Such that I can test b & c above. Hows best?

Thanks in advance!

More information about the rspec-users mailing list