2

I'm writing a gem to add support for SOAP services to Ruby (I hate myself for doing this but, you know, legacy systems are feeling lonely and gotta talk to someone), and I'm wondering if there's a way I can write some tests using Savon as a client library.

My question is: how can I tell Savon to call the WebService using Rack::Test?

The gem sources are hosted here: https://github.com/elementar/shapewear

Fábio Batista
  • 25,002
  • 3
  • 56
  • 68

1 Answers1

3

I ended up using the WebMock gem. Here's the result:

https://github.com/elementar/shapewear/blob/master/spec/shapewear/savon_usage_spec.rb

describe Shapewear do
  describe "usage with SOAP clients" do
    before do
      stub_request(:get, "http://services.example.com/complete/soap/wsdl") \
        .to_return :body => CompleteService.to_wsdl, 
                   :headers => {'Content-Type' => 'application/xml'}

      stub_request(:post, "http://services.example.com/complete/soap") \
        .to_return :body => lambda { |r| CompleteService.serve(r) }, 
                   :headers => {'Content-Type' => 'application/xml'}
    end

    it "should work with Savon" do
      client = Savon::Client.new 'http://services.example.com/complete/soap/wsdl'
      response = client.request :echo_in_uppercase, :xmlns => 'http://services.example.com/v1' do
        soap.body = {:text => 'uppercase text'}
      end

      response.body[:echo_in_uppercase_response][:body].should == 'UPPERCASE TEXT'
    end
  end
end
Fábio Batista
  • 25,002
  • 3
  • 56
  • 68