This is Google's cache of https://gist.github.com/mwlang/8de20866c2cf0b29b978. It is a snapshot of the page as it appeared on Apr 13, 2024 04:47:58 GMT. The current page could have changed in the meantime. Learn more.
Full versionText-only versionView source
Tip: To quickly find your search term on this page, press Ctrl+F or ⌘-F (Mac) and use the find bar.
Below is an example of using Savon to test SOAP endpoints of a Rails app that uses Wash out. The Savon approach works, but Savon likes to mangle the XML you feed it by wrapping it in the SOAP Envelope and Body tags. Therefore, I'm trying to duplicate with Faraday what's working with Savon so I can fully control the XML being fed to the SOAP endpoint. HTTPI is mounting the app to "http://app" such that Savon just needs "http://app/soap/wsdl" to connect. Faraday, however, says it was fed an invalid node or server name. Is there a Faraday friendly way to mount the app within the testing framework? · GitHub
Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created January 21, 2015 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwlang/8de20866c2cf0b29b978 to your computer and use it in GitHub Desktop.
Save mwlang/8de20866c2cf0b29b978 to your computer and use it in GitHub Desktop.
Below is an example of using Savon to test SOAP endpoints of a Rails app that uses Wash out. The Savon approach works, but Savon likes to mangle the XML you feed it by wrapping it in the SOAP Envelope and Body tags. Therefore, I'm trying to duplicate with Faraday what's working with Savon so I can fully control the XML being fed to the SOAP endp…
Failure/Error: response = post_xml(:stock_update, "single_item")
Faraday::ConnectionFailed:
getaddrinfo: nodename nor servname provided, or not known
# /Users/mwlang/.rvm/gems/ruby-2.1.2/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
# /Users/mwlang/.rvm/gems/ruby-2.1.2/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
# /Users/mwlang/.rvm/gems/ruby-2.1.2/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
# /Users/mwlang/.rvm/gems/ruby-2.1.2/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
# /Users/mwlang/.rvm/gems/ruby-2.1.2/gems/faraday-0.9.0/lib/faraday/connection.rb:177:in `post'
def faraday_connection
Faraday.new(:url => "http://app/soap/wsdl") do |faraday|
faraday.adapter Faraday.default_adapter
end
end
def faraday_xml(service, fixture_name)
response = faraday_connection.post do |req|
req.url '/soap/action'
req.headers['Content-Type'] = 'text/xml; charset="utf-8"'
req.headers['SOAPAction'] = '/soap/action/stock_update'
req.body = read_fixture(service, fixture_name)
end
response.body
end
HTTPI.logger = Logger.new(open("/dev/null", 'w'))
HTTPI.adapter = :rack
HTTPI::Adapter::Rack.mount 'app', Webservice::Application
def savon_xml(method, xml)
savon = Savon::Client.new(wsdl: "http://app/soap/wsdl")
hash_str = savon.call(method, :message => xml).to_hash["#{method}_response".to_sym]
result = eval(hash_str[:value]) rescue hash_str
result.is_a?(String) ? {value: result} : result
end
require 'rails_helper'
describe SoapController, :type => :controller do
describe "stock_update" do
it "should process xml" do
response = savon_xml(:update_stock, Fixture.stock_update(:single_item))
expect(response[:value]).to eq "success!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment