Ruby 1.8 provides Ping.pingecho, but it was removed in 1.9. So we try requiring it, and if that fails, define it ourselves.
A Net::HTTP response that has already been read raises an IOError when read_body is called with a destination string or block.
This causes a problem when VCR records a response--it reads the body before yielding the response, and if the code that is consuming the HTTP requests uses read_body, it can cause an error.
This is a bit of a hack, but it allows a Net::HTTP response to be "re-read" after it has aleady been read. This attemps to preserve the behavior of read_body, acting just as if it had never been read.
Attempt to use psych if it is available.
# File lib/vcr.rb, line 82 def config yield VCR::Config http_stubbing_adapter.check_version! http_stubbing_adapter.set_http_connections_allowed_to_default http_stubbing_adapter.ignored_hosts = VCR::Config.ignored_hosts end
# File lib/vcr.rb, line 46 def current_cassette cassettes.last end
# File lib/vcr.rb, line 66 def eject_cassette cassette = cassettes.pop cassette.eject if cassette cassette end
# File lib/vcr.rb, line 94 def http_stubbing_adapter @http_stubbing_adapter ||= begin if [:fakeweb, :webmock].all? { |l| VCR::Config.http_stubbing_libraries.include?(l) } raise ArgumentError.new("You have configured VCR to use both :fakeweb and :webmock. You cannot use both.") end adapters = VCR::Config.http_stubbing_libraries.map { |l| adapter_for(l) } raise ArgumentError.new("The http stubbing library is not configured.") if adapters.empty? HttpStubbingAdapters::MultiObjectProxy.for(*adapters) end end
# File lib/vcr.rb, line 147 def ignore_cassettes? @ignore_cassettes end
# File lib/vcr.rb, line 50 def insert_cassette(name, options = {}) if turned_on? if cassettes.any? { |c| c.name == name } raise ArgumentError.new("There is already a cassette with the same name (#{name}). You cannot nest multiple cassettes with the same name.") end cassette = Cassette.new(name, options) cassettes.push(cassette) cassette elsif !ignore_cassettes? message = "VCR is turned off. You must turn it on before you can insert a cassette. " + "Or you can use the `:ignore_cassette => true` option to completely ignore cassette insertions." raise TurnedOffError.new(message) end end
# File lib/vcr.rb, line 106 def record_http_interaction(interaction) return unless cassette = current_cassette return if VCR::Config.uri_should_be_ignored?(interaction.uri) cassette.record_http_interaction(interaction) end
# File lib/vcr.rb, line 123 def turn_off!(options = {}) if VCR.current_cassette raise CassetteInUseError.new("A VCR cassette is currently in use. You must eject it before you can turn VCR off.") end @ignore_cassettes = options[:ignore_cassettes] invalid_options = options.keys - [:ignore_cassettes] if invalid_options.any? raise ArgumentError.new("You passed some invalid options: #{invalid_options.inspect}") end VCR.http_stubbing_adapter.http_connections_allowed = true @turned_off = true end
# File lib/vcr.rb, line 138 def turn_on! VCR.http_stubbing_adapter.set_http_connections_allowed_to_default @turned_off = false end
# File lib/vcr.rb, line 113 def turned_off(options = {}) turn_off!(options) begin yield ensure turn_on! end end
Generated with the Darkfish Rdoc Generator 2.