Created
March 23, 2012 20:01
-
-
Save DanKnox/2174394 to your computer and use it in GitHub Desktop.
Mocked Savon Client for testing ReD web service
This file contains 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 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