Skip to content

Instantly share code, notes, and snippets.

@DanKnox
Created March 23, 2012 20:01
Show Gist options
  • Save DanKnox/2174394 to your computer and use it in GitHub Desktop.
Save DanKnox/2174394 to your computer and use it in GitHub Desktop.
Mocked Savon Client for testing ReD web service
class MockRedClient
attr_accessor :original_self, :soap
def request(*args,&block)
self.soap = SoapMock.new
builder = evaluate(&block) if block
MockRedResponse.new
end
def evaluate(&block)
self.original_self = eval "self", block.binding
instance_eval &block
end
def method_missing(method, *args, &block)
super unless original_self
original_self.send method, *args, &block
end
end
class MockRedResponse
FRAUD_STATUS = "ACCEPT"
def to_hash
{:lpcall_response=>{
:res_array=>
{:item=>[]} # response truncated for brevity
},
:"@soap_env:encoding_style"=>"http://schemas.xmlsoap.org/soap/encoding/"
}
end
def to_xml
to_hash
end
end
class SoapMock
attr_accessor :body
def to_xml
body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment