Can't test against a class which extends Savon::Model
It appears that you can't test against a class which extends Savon::Model.
I have written savon_model_spec_fail.rb to demonstrate that instead of mocking the get_user SOAP action, the call is passed on to httpclient:
$ rspec savon_model_spec_fail.rb
.W, [2012-07-16T23:15:31.268851 #22655] WARN -- : HTTPI executes HTTP GET using the httpclient adapter
FW, [2012-07-16T23:15:32.375432 #22655] WARN -- : HTTPI executes HTTP GET using the httpclient adapter
F
Failures:
1) with model mocks a SOAP request for an instance method
Failure/Error: client.request(:get_user)
SocketError:
getaddrinfo: nodename nor servname provided, or not known (http://service.example.com:80)
# ./savon_model_spec_fail.rb:32:in `get_user_class'
# ./savon_model_spec_fail.rb:47:in `block (2 levels) in <top (required)>'
2) with model mocks a SOAP request for an class method
Failure/Error: client.request(:get_user)
SocketError:
getaddrinfo: nodename nor servname provided, or not known (http://service.example.com:80)
# ./savon_model_spec_fail.rb:36:in `get_user_instance'
# ./savon_model_spec_fail.rb:51:in `block (2 levels) in <top (required)>'
Finished in 1.19 seconds
3 examples, 2 failures
Failed examples:
rspec ./savon_model_spec_fail.rb:46 # with model mocks a SOAP request for an instance method
rspec ./savon_model_spec_fail.rb:50 # with model mocks a SOAP request for an class method
I just ran this with a debugger. The problem is that Savon attempts to retrieve the WSDL document you specified. Since you specified a remote location for the document, it opens an HTTP connection to retrieve it. Of course the document does not actually exist, so your test fails.
[29, 38] in /Users/tim/.rvm/gems/ruby-1.9.3-p194/gems/savon-1.1.0/lib/savon/wasabi/document.rb
29
30 # Resolves and returns the raw WSDL document.
31 def resolve_document
32 case document
33 when /^http[s]?:/ then
=> 34 response = HTTPI.get(request)
that sounds about right. savon_spec stubs your soap requests, but if you depend on a remote wsdl, savon still needs to fetch it to set up the client.