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!
Evgeni Dzhelyov
2012-Jan-15 16:49 UTC
[rspec-users] How to mock out a WEBrick::HTTPServer?
I read your pastie and your Proxy class is tightly coupled with Webrick, you should decouple it and supply mocked object in the test environment. Some people use approach like this: class A def initialize(server = WEBrick::HTTPServer) end end And in test env initialize the A class like this: A.new(MockedHTTPServer)
Maybe Matching Threads
- Troll - A Rails plugin for making webservice mocking easier
- FakeWeb test helper for Net::HTTP / open-uri web requests
- Patch: Allow overriding of handler dispatch in Mongrel::HttpServer
- [Patch] HttpServer.port reports the bound port
- Issues after removal of rpsec plugins and gem install