3

I have part of my rails 2 webservice application which is used as SOAP service (historical reasons, rest of app is REST). Just two operations AddLead and ShowLead, with wsdl on /soap/wsdl.

I want to test this operations by Rspec integrations tests. Trying to use Savon gem (/spec/integration/soap_spec.rb):

require "spec_helper"
require 'rubygems'
require 'savon'

describe "Leads" do

  before(:all) do
    wsdl=   "http://localhost:3000/soap/wsdl"
    wsdl = "http://www.example.com/soap/wsdl"
    @client = Savon.client(:wsdl => wsdl )

    puts("WSDL actions: #{@client.operations}")
  end
end

But I can not find which URL I should use to point to WSDL.

URL localhost:3000 does not work, ending with error:

 Errno::ECONNREFUSED in 'Leads before(:all)'
 Connection could not be made, because target server it actively denied. - connect(2)

URL www.example.com (which is output from test url helpers) does not work either, ending with error:

   Wasabi::Resolver::HTTPError in 'Leads before(:all)'
   Error: 302

Any ideas?

Foton

Foton
  • 1,197
  • 13
  • 24
  • Also tried just realtive path `/soap/wsdl` (as used in REST integration Rspec tests; eg. `get "resource/id.xml"`). Result was: `Errno::ENOENT in 'Leads before(:all)' No such file or directory - /soap/wsdl` – Foton Jun 19 '13 at 08:55
  • The `:wsdl` option expects the URL to the WSDL document of your service. I'm not sure which port Rails uses during tests (try `http://test.host:80`), but I would suggest to use Rails' URL-Helpers to set the corrent host and port for you. – rubiii Jul 01 '13 at 08:41
  • Helper `soap_wsdl_url()` points to `http://www.example.com/soap/wsdl`. This adres I already tried with Wasabi::Resolver::HTTPError (see above). – Foton Jul 01 '13 at 09:37
  • No idea. Did you try to hit the URL with some HTTP client? Just to make sure it responds correctly. – rubiii Jul 01 '13 at 11:57
  • If you google the `Errno::ECONNREFUSED` error message, you may find something related to your setup. If that doesn't work out for you, please try to reproduce the problem in a new Rails app with just the code needed for this error to occur and push it to GitHub. – rubiii Jul 01 '13 at 12:02

1 Answers1

3

Try the following link: http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/

Inside of your describe block use the HTTPI rack adapter, and then configure that adapter to mount your application. This will give you the ability to use a specific url.

require 'spec_helper'
require 'savon'

describe API::MyService do
  HTTPI.adapter = :rack
  HTTPI::Adapter::Rack.mount 'application', MyApp::Application

  it 'can get a response' do
    application_base = "http://application"
    client = Savon::Client.new({:wsdl => application_base + '/soap/wsdl' })
    ...
    ...
  end
  ...
vic700208
  • 41
  • 6