Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base class for ExpectationError makes it hard for tests to fail #428

Closed
dbyron0 opened this issue Apr 9, 2013 · 4 comments
Closed

base class for ExpectationError makes it hard for tests to fail #428

dbyron0 opened this issue Apr 9, 2013 · 4 comments
Milestone

Comments

@dbyron0
Copy link

dbyron0 commented Apr 9, 2013

I've got code in production that basically does

begin
  client = Savon.client
  client.call
rescue Savon::Error => e
  log it and move on
  no raise statement
end

Unfortunately, if a test fails that I set up with Savon::SpecHelper, it raises a Savon::ExpectationError which inherits from Savon::Error so I never see the test failure.

The idea of checking for Savon::ExpectationError in production code feels unsavory. What do you think about changing Savon::ExpectationError to inherit from ::Exception instead?

@rubiii
Copy link
Contributor

rubiii commented Apr 10, 2013

i think i know what you mean, but could you provide a spec describing the problem?

@dbyron0
Copy link
Author

dbyron0 commented Apr 10, 2013

I'll give it a shot. I have the repo cloned on my machine. I figured I'd start by running the existing tests. I'm getting some failures that I don't understand, both because my disk isn't full and because I'm running on OS X. Any ideas?

$ bundle install
$ bundle exec rspec
.....F..........F..............................................................................................................................................................................................................................................F.....

Failures:

  1. Stockquote example returns the result in a CDATA tag
    Failure/Error: response = client.call(:get_quote, :message => { :symbol => "AAPL" })
    Savon::SOAPFault:
    (soap:Server) System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.IO.IOException: There is not enough space on the disk.
      at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
      at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
      at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)
      at System.IO.FileStream.Dispose(Boolean disposing)
      at System.IO.Stream.Close()
      at System.IO.StreamWriter.Dispose(Boolean disposing)
      at System.IO.TextWriter.Dispose()
      at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
      at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
      at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
      at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
      at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
      at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
      at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
      at System.Web.Services.Protocols.SoapServerType..ctor(Type type, WebServiceProtocols protocolsSupported)
      at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
      at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
      --- End of inner exception stack trace ---
 # ./lib/savon/response.rb:70:in `raise_soap_and_http_errors!'
 # ./lib/savon/response.rb:13:in `initialize'
 # ./lib/savon/operation.rb:53:in `new'
 # ./lib/savon/operation.rb:53:in `call'
 # ./lib/savon/client.rb:36:in `call'
 # ./spec/integration/stockquote_example_spec.rb:18:in `block (2 levels) in <top (required)>'
  1. Temperature example converts 30 degrees celsius to 86 degrees fahrenheit
    Failure/Error: response = client.call(:convert_temp) do
    Savon::SOAPFault:
    (soap:Server) System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.IO.IOException: There is not enough space on the disk.
      at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
      at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
      at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer)
      at System.IO.FileStream.Dispose(Boolean disposing)
      at System.IO.Stream.Close()
      at System.IO.StreamWriter.Dispose(Boolean disposing)
      at System.IO.TextWriter.Dispose()
      at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
      at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
      at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
      at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
      at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
      at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
      at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
      at System.Web.Services.Protocols.SoapServerType..ctor(Type type, WebServiceProtocols protocolsSupported)
      at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
      at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
      --- End of inner exception stack trace ---
 # ./lib/savon/response.rb:70:in `raise_soap_and_http_errors!'
 # ./lib/savon/response.rb:13:in `initialize'
 # ./lib/savon/operation.rb:53:in `new'
 # ./lib/savon/operation.rb:53:in `call'
 # ./lib/savon/client.rb:36:in `call'
 # ./spec/integration/temperature_example_spec.rb:24:in `block (2 levels) in <top (required)>'
  1. Savon knows the message tag for :edialog
    Failure/Error: expect(message_tag).to eq(['uri:dataupload.ws.sdk.edialog.com', 'listAllDataColumns'])
   expected: ["uri:dataupload.ws.sdk.edialog.com", "listAllDataColumns"]
        got: ["uri:ws.sdk.edialog.com", "listAllDataColumns"]

   (compared using ==)
 # ./spec/savon/features/message_tag_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 10.01 seconds
261 examples, 3 failures

Failed examples:

rspec ./spec/integration/stockquote_example_spec.rb:5 # Stockquote example returns the result in a CDATA tag
rspec ./spec/integration/temperature_example_spec.rb:5 # Temperature example converts 30 degrees celsius to 86 degrees fahrenheit
rspec ./spec/savon/features/message_tag_spec.rb:10 # Savon knows the message tag for :edialog

Randomized with seed 34968

@dbyron0
Copy link
Author

dbyron0 commented Apr 10, 2013

I think I've got it. I added this to spec/savon/mock_spec.rb:

it "allows code to rescue Savon::Error and still report test failures" do
message = { :username => "luke" }
savon.expects(:find_user).with(:message => message).returns("")

expect do
  begin
    new_client.call(:find_user)
  rescue Savon::Error => e
    puts "any real error (e.g. SOAP fault or HTTP error) is OK in the big picture, move on"
  end
end.to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
                                          "  with this message: #{message.inspect}\n" \
                                          "Received a request to the :find_user operation\n" \
                                          "  with no message.")

end

@rubiii
Copy link
Contributor

rubiii commented Apr 20, 2013

fixed on master. this will be released with v2.2.0.
thanks @dbyron0

@rubiii rubiii closed this as completed Apr 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants