2012-01-03 79 views
1

我正在写一个gem来向Ruby添加对SOAP服务的支持(我讨厌自己这样做,但是,你知道,遗留系统感到孤独并且需要与某人交谈),而且,我想知道是否有办法使用Savon作为客户端库来编写一些测试。用Savon测试本地Web服务

我的问题是:我如何告诉Savon使用Rack::Test调用WebService?

宝石的来源都在这里举行:https://github.com/elementar/shapewear

+1

通过https://github.com/rubiii取得联系,我们会谈论它! – rubiii 2012-01-03 19:43:49

回答

3

我结束了使用WebMock宝石。这里的结果:

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