Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:29
Show Gist options
  • Save cantremember/2167255 to your computer and use it in GitHub Desktop.
Save cantremember/2167255 to your computer and use it in GitHub Desktop.
silly mocking of Net::HTTPResponse
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