Foton
Foton

Reputation: 1287

Integration/request rspec test of my SOAP service

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

Upvotes: 3

Views: 2068

Answers (1)

vic700208
vic700208

Reputation: 41

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
  ...

Upvotes: 3

Related Questions