kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

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

Closed tubbo closed 11 years ago

tubbo commented 12 years ago

My tests were failing with this error:

YoutubeVideoTest
    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:

#<VCR::Errors::UnhandledHTTPRequestError: 

================================================================================
An HTTP request has been made that VCR does not know how to handle:
  GET http://gdata.youtube.com/feeds/api/videos/ggg3C87UVCY?key=my-developer-key&v=2

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].

[1] https://www.relishapp.com/myronmarston/vcr/v/2-2-3/docs/getting-started
[2] https://www.relishapp.com/myronmarston/vcr/v/2-2-3/docs/configuration/allow-http-connections-when-no-cassette
[3] https://www.relishapp.com/myronmarston/vcr/v/2-2-3/docs/configuration/ignore-request
================================================================================

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
        raise OpenURI::HTTPError.new(e.io.status[0],e)
      rescue
        @content = content

      end

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

chebyte commented 12 years ago

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

Odaeus commented 11 years ago

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 11 years ago

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.