我正在编写一个 gem 来为 Ruby 添加对 SOAP 服务的支持(我讨厌自己这样做,但是,你知道,遗留系统感到孤独,必须与某人交谈),我想知道是否有一种方法可以编写一些使用 Savon 作为客户端库的测试。
我的问题是:我如何告诉 Savon 使用 调用 WebService Rack::Test
?
我正在编写一个 gem 来为 Ruby 添加对 SOAP 服务的支持(我讨厌自己这样做,但是,你知道,遗留系统感到孤独,必须与某人交谈),我想知道是否有一种方法可以编写一些使用 Savon 作为客户端库的测试。
我的问题是:我如何告诉 Savon 使用 调用 WebService Rack::Test
?
我最终使用了WebMock gem。结果如下:
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