Skip to content
Browse files

Add comments

  • Loading branch information...
1 parent 68e6ae8 commit d80e6428e8b643cbec9aea2b2c64a365c9613373 @wycats wycats committed Mar 24, 2010
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/artifice.rb
View
15 lib/artifice.rb
@@ -39,6 +39,8 @@ def self.replace_net_http(value)
end
module Net
+ # This is an internal object that can receive Rack requests
+ # to the application using the Rack::Test API
class RackRequest
include Rack::Test::Methods
attr_reader :app
@@ -53,6 +55,9 @@ class << self
attr_accessor :endpoint
end
+ # Net::HTTP uses a @newimpl instance variable to decide whether
+ # to use a legacy implementation. Since we are subclassing
+ # Net::HTTP, we must set it
@newimpl = true
# We don't need to connect, so blank out this method
@@ -68,6 +73,7 @@ def connect
# @param [optional, String, #read] body This should
# be sent as "rack.input". If it's a String, it will
# be converted to a StringIO.
+ # @return [Net::HTTPResponse]
#
# @yield [Net::HTTPResponse] If a block is provided,
# this method will yield the Net::HTTPResponse to
@@ -90,6 +96,15 @@ def request(req, body = nil, &block)
private
+ # This method takes a Rack response and creates a Net::HTTPResponse
+ # Instead of trying to mock HTTPResponse directly, we just convert
+ # the Rack response into a String that looks like a normal HTTP
+ # response and call Net::HTTPResponse.read_new
+ #
+ # @param [Array(#to_i, Hash, #each)] response a Rack response
+ # @return [Net::HTTPResponse]
+ # @yield [Net::HTTPResponse] If a block is provided, yield the
+ # response to it after the body is read
def make_net_http_response(response)
status, headers, body = response.status, response.headers, response.body

0 comments on commit d80e642

Please sign in to comment.
Something went wrong with that request. Please try again.