Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created November 20, 2012 21:46
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 JEG2/4121410 to your computer and use it in GitHub Desktop.
Save JEG2/4121410 to your computer and use it in GitHub Desktop.
Another Typhoeus VCR Interaction Bug
require "bundler/setup"
require "vcr"
require "typhoeus"
VCR.configure do |config|
config.cassette_library_dir = File.join( File.dirname(__FILE__),
"vcr_cassettes" )
config.hook_into :typhoeus
end
describe "Typhoeus used with VCR" do
it "should work with nested queuing" do
VCR.use_cassette("nested") do
success = false
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new("http://xkcd.com/")
request.on_success do |response|
nested = Typhoeus::Request.new("http://yahoo.com/")
nested.on_success do |_|
success = true
end
hydra.queue(nested)
end
hydra.queue(request)
hydra.run
expect(success).to be_true
end
end
end
# $ rspec bug_spec.rb
# F
# Failures:
# 1) Typhoeus used with VCR should work with nested queuing
# Failure/Error: hydra.run
# NameError:
# instance variable @__typed_vcr_request not defined
# # ./bug_spec.rb:26:in `block (3 levels) in <top (required)>'
# # ./bug_spec.rb:13:in `block (2 levels) in <top (required)>'
# Finished in 0.22194 seconds
# 1 example, 1 failure
# Failed examples:
# rspec ./bug_spec.rb:12 # Typhoeus used with VCR should work with nested queuing
source :rubygems
gem "typhoeus", "~> 0.5.2"
gem "vcr", "~> 2.3.0"
gem "rspec"
@hanshasselberg
Copy link

Please change on_success to on_complete since a redirect doesn't count as a successful response: https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/response/status.rb#L49. Or add followlocation: true.

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