Created
August 7, 2012 00:11
-
-
Save jrochkind/3279823 to your computer and use it in GitHub Desktop.
VCR, WebMock, HTTPClient weirdness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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