Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Forked from subdigital/savon_vcr.rb
Created January 27, 2011 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/799403 to your computer and use it in GitHub Desktop.
Save myronmarston/799403 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'httpclient'
require 'vcr'
require 'savon'
require 'test/unit'
VCR.config do |c|
c.cassette_library_dir = 'fixtures/cassettes'
c.stub_with :webmock
end
class VCRSavonTest < Test::Unit::TestCase
def setup
path = File.expand_path("../fixtures/cassettes", __FILE__)
`rm -rf #{path}`
end
def assert_cassette_exists(cassette_name)
file = "fixtures/cassettes/#{cassette_name}.yml"
assert(File.exists?(file), "Cassette #{file} not found")
end
#THIS SUCCEEDS
def test_it_works_with_basic_http_client
VCR.use_cassette('test_httpclient_request', :record => :new_episodes) do
client = HTTPClient.new
response = client.get("http://flux88.com")
assert_not_nil response
end
assert_cassette_exists('test_httpclient_request')
end
#THIS FAILS
def test_it_should_write_a_cassette_with_savon
VCR.use_cassette('savon_test_cassette', :record => :new_episodes) do
client = Savon::Client.new do
wsdl.document = 'http://www.webservicex.net/MortgageIndex.asmx?wsdl'
end
response = client.request :get_mortgage_index_monthly do |soap, wsdl, http|
http.headers['SOAPAction'] = 'http://www.webserviceX.NET/GetCurrentMortgageIndexByWeekly'
end
assert_not_nil response
end
assert_cassette_exists('savon_test_cassette')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment