Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created January 30, 2011 04:56
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save igrigorik/802553 to your computer and use it in GitHub Desktop.
Save igrigorik/802553 to your computer and use it in GitHub Desktop.
Mocking with WebMock and VCR
require 'rubygems'
require 'test/unit'
require 'em-http'
require 'vcr'
VCR.config do |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.http_stubbing_library = :webmock
end
class VCRTest < Test::Unit::TestCase
def make_http_request(url)
http = nil
EventMachine.run do
http = EventMachine::HttpRequest.new(url).get
http.callback { EventMachine.stop }
end
http
end
def test_example_dot_com
VCR.use_cassette('example', :record => :new_episodes) do
http = make_http_request("http://example.com/")
assert_match /You have reached this web page by typing.*example\.com/, http.response
end
end
end
@myers
Copy link

myers commented Jul 14, 2014

Could we see an example of testing the handling of a Errno::ETIMEDOUT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment