public
Last active

Mocking with WebMock and VCR

  • Download Gist
em-http-vcr.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.