Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Forked from jrochkind/test_it.rb
Created August 7, 2012 02:18
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/3280755 to your computer and use it in GitHub Desktop.
Save myronmarston/3280755 to your computer and use it in GitHub Desktop.
VCR, WebMock, HTTPClient weirdness
require 'httpclient'
require 'vcr'
require 'webmock'
require 'test/unit'
# To allow us to do real HTTP requests in a VCR.turned_off, we
# have to tell webmock to let us.
WebMock.allow_net_connect!
VCR.configure do |c|
c.cassette_library_dir = 'test/vcr_cassettes'
# webmock needed for HTTPClient testing
c.hook_into :webmock
end
class VcrTest < Test::Unit::TestCase
@@http_client = HTTPClient.new
def setup
@body = "{ \"UserId\":\"user\", \"Password\":\"password\" } "
# this was originally a real vendor URL, but test is reproducible
# even with this fake URL that isn't connectable.
# But reproduces with a real URL that
# accepts POSTs too.
@url = "http://example.org"
end
def test_get_one
VCR.use_cassette("test_one") do
response = @@http_client.post(@url, @body)
end
end
def test_get_two
VCR.use_cassette("test_two") do
response = @@http_client.post(@url, @body)
end
end
# If this VCR.turned_off is present, for some reason we get
# the "appears to be a bug in Webmock's" warning even when
# re-playing pre-recorded cassettes, otherwise only when
# recording.
def test_aaa_turned_off
VCR.turned_off do
response = @@http_client.post(@url, @body)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment