Nonsensical error when VCR can't find a cassette #108

tubbo opened this Issue Jul 17, 2012 · 3 comments


None yet

4 participants

tubbo commented Jul 17, 2012

My tests were failing with this error:

    ERROR (0:00:00.728) test_find_youtube_video_by_url
          undefined method `at' for nil:NilClass
        @ /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/youtube_it-2.1.7/lib/youtube_it/parser.rb:380:in `parse_entry'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/youtube_it-2.1.7/lib/youtube_it/parser.rb:375:in `parse_content'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/youtube_it-2.1.7/lib/youtube_it/parser.rb:17:in `parse'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/youtube_it-2.1.7/lib/youtube_it/client.rb:96:in `video_by'
          app/support/video_handlers/youtube_video.rb:10:in `initialize'
          test/unit/video_handlers/youtube_video_test.rb:4:in `new'
          test/unit/video_handlers/youtube_video_test.rb:4:in `block in <class:YoutubeVideoTest>'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:473:in `_run__291905445358915445__setup__4610334597486491381__callbacks'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /Users/tom/.rvm/gems/ruby-1.9.3-p125@elocal/gems/activesupport-3.2.6/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

That is actually hiding the real error, which is:


An HTTP request has been made that VCR does not know how to handle:

There is currently no cassette in use. There are a few ways
you can configure VCR to handle this request:

  * If you want VCR to record this request and play it back during future test
    runs, you should wrap your test (or this portion of your test) in a
    `VCR.use_cassette` block [1].
  * If you only want VCR to handle requests made while a cassette is in use,
    configure `allow_http_connections_when_no_cassette = true`. VCR will
    ignore this request since it is made when there is no cassette [2].
  * If you want VCR to ignore this request (and others like it), you can
    set an `ignore_request` callback [3].


It should show the VCR error, as it took a bit of confusion and debugging to figure out where this was happening. I believe the problem code is the following:

class YouTubeIt
  module Parser #:nodoc:
    class FeedParser #:nodoc:
      def initialize(content)
        @content = (content =~ URI::regexp(%w(http https)) ? open(content).read : content)

      rescue OpenURI::HTTPError => e
        @content = content


We can't be rescuing VCR errors here. Instead, we should be using a begin/rescue/end and rescuing OpenURI::HTTPError.

chebyte commented Sep 21, 2012

mmmm what version of ruby do you have? for me and travis works perfect

Odaeus commented Oct 26, 2012

I can confirm this error, ruby 1.9.3p194.
It occurs when you have a cassette already recorded and then amend or add to the test which causes VCR to raise an exception describing how to handle the situation.
I can supply a simple patch if you like?

tubbo commented Oct 29, 2012

We are using 1.9.3-p125, but are considering upgrading to the latest. I'll let you guys know if this continues after we upgrade.

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