views:

641

answers:

3

As a learning experience I'm developing a small Rails application that is supposed to query an existing SOAP API/web service (using the handsoap gem) and will simply present the information gathered there to a user.

I like using rspec and am getting used to cucumber for testing my applications. The part that has me stumped is how to test the interaction with the API, i.e. the 'non-presentation' part of passing back and forth XML requests and responses.

Any tips and pointers are very much appreciated!

Thanks!

A: 

I'm assuming you're talking about functional/integration style tests and not unit tests in which case I would probably consider mocking the interface for the web service and unit testing the code on a lower level.

But to return to cucumber. As Aslak Hellesøy points out in Stack overflow q 810410 there is nothing that should prevent you from doing this. When you have written the scenarios for what behaviour you are actually going to test you just have to instantiate the right objects in the step definitions and call the appropriate methods. Possibly also combining it with a few asserts on return values or content if that is what you need. See Rspec expectations for how to load rspec's should() with cucumber.

Knut Haugen
+1  A: 

Take a look at fakeweb gem.

It helps to stub network interoperability, i.e. you can create test responses:

  FakeWeb.register_uri(:get, "http://example.com/test1", :body => "Hello World!")

and disable ability to send http requests:

  FakeWeb.allow_net_connect = false
  Net::HTTP.get(URI.parse("http://example.com/"))
  => raises FakeWeb::NetConnectNotAllowedError
edbond
A: 

With the newest version of Handsoap, you can use a mock http-driver, to mock out at the http-level. See: Http::HttpMock and the example in tests/account_test.rb

troelskn