2012-01-03 80 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