Created
March 23, 2012 05:29
-
-
Save cantremember/2167255 to your computer and use it in GitHub Desktop.
silly mocking of Net::HTTPResponse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net::HTTPResponse | |
def self.mock(ops={}) | |
# defaults | |
ops = { | |
:http_version => '1.1', | |
:code => '200', | |
:message => 'OK', | |
:body => nil, | |
}.merge(ops || {}) | |
# construct | |
###clazz = CODE_TO_OBJ[ops[:code]] | |
clazz = self | |
response = clazz.new(ops[:http_version], ops[:code], ops[:message]) | |
# inject | |
ops.each do |k, v| | |
response.instance_variable_set "@#{k}".to_sym, v | |
end | |
# mockulate | |
response.instance_eval %q{ | |
def body; @body; end | |
} | |
response | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment