How to mock out a WEBrick::HTTPServer?

partial code :

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 “”

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

Thanks in advance!

I read your pastie and your Proxy class is tightly coupled with
Webrick, you should decouple it and supply mocked object in the test

Some people use approach like this:

class A
def initialize(server = WEBrick::HTTPServer)

And in test env initialize the A class like this:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs