Testing SOAP service clients with test/unit

1 view
Skip to first unread message

brian doll

unread,
Jun 9, 2008, 1:36:02 PM6/9/08
to soap4r
I've been working with soap4r for a while now, and have had a good bit
of success in quickly turning around ruby soap clients for the various
services my team uses internally. I've built a gem that includes some
base classes, utilities and the service clients. Each of the clients
works as expected. Hurray, right?

Not so fast. It goes without saying that having a solid test suite
for these clients is imperative. I've got a few TestCase classes that
get run through rake and.... they don't work.

Let's take a simple example that works perfectly in irb, or run as a
script from the command line:
(Note: names changed to protect the innocent.)
####
require 'rubygems'
gem 'soap4r'
require 'my_service_client'

WSDL_LOCATION = "http://localhost:8080"
puts MyServiceClient.instance.get_something("foo")
####

This works. Essentially this script just sets up the dependencies
(note the gem 'soap4r' bit), sets the default location for my WSDLs
and prints out the results of a method call to the instance
(Singleton) of MyServiceClient.

Now, let's do the same thing in a unit test:
####
require 'rubygems'
gem 'soap4r'
require 'my_service_client'

WSDL_LOCATION = "http://localhost:8080"

class TestMyServiceClient < Test::Unit::TestCase

def test_get_something
assert_equal("bar", MyServiceClient.instance.get_something("foo"))
end

end
####

This, unfortunately, does not work. The stream of junk to the screen
and the error message indicate that the soap4r gem has not been
loaded. The results of this unit test are identical to the irb test
if I were to remove the "gem 'soap4r'" line.

Oddly enough, when I repeat that line within the test class (after the
class declaration or inside a setup method, of all places), it returns
false, which indicates it has already been loaded.

So, I ask you.. how do you test your soap4r soap clients? Might you
have some insight into how best to setup the various dependencies
required to run soap4r clients within test/unit classes? Perhaps you
could share a test class or your own? I'd greatly appreciate any
suggestions...

cheers,
b


Reply all
Reply to author
Forward
0 new messages