11

I have a very simple module I'm testing with Ruby using the VCR gem.

I've configured VCR according to the documentation but cannot seem to get a cassette to record in the cassette directory. I've even changed the permissions on the cassette directory to 777 just in case. The really strange thing is, I've completely removed the cassette directory, run the specs, and then a new cassette directory is created.

I'm using Typhoeus 0.4.2 with Hydra. I can't upgrade Typhoeus at the moment.

The relevant code:

require 'rspec'                                                                     
require 'vcr'                                                                       
require_relative File.join("..", "crawl_handler")                                   

VCR.configure do |c|                                                                
  c.cassette_library_dir = "spec/vcr_cassettes"                                     
  c.hook_into :fakeweb                                                              
  c.allow_http_connections_when_no_cassette = false                                 
end

... # => other describe statements
 describe "#handle_http_response" do                                               
    before(:each) do                                                                
      get_some_response = lambda {                                                  
        # NOTE: typhoeus v. 0.5 is MUCH less setup :)                               
        VCR.use_cassette("bme") do                                                  
          request = Typhoeus::Request.new("www.bing.com")                           
          hydra = Typhoeus::Hydra.new                                               
          hydra.queue(request)                                                      
          hydra.run                                                                 
          response = request.response                                               
        end                                                                         
      }                                                                             
      @message = @subject.handle_http_response("www.bing.com", get_some_response.call)    
    end                                                                             

    it "returns a message hash" do                                                  
      @message.should be_kind_of Hash                                               
    end  

    ...

I have no idea why cassettes aren't being written.

brycemcd
  • 4,343
  • 3
  • 26
  • 29
  • 5
    +1 for title. I was going to closevote as off topic and recommend you clean the record heads (or upgrade to Blu-Ray), but I guess you're talking about Ruby code :) – Michael Berkowski Dec 02 '12 at 01:53
  • 2
    LOL! I was so wrapped up in trying to solve the issue that I didn't even notice that. For that problem, I just blew on the tape, unplugged it and plugged it back in. – brycemcd Dec 02 '12 at 23:24

1 Answers1

11

The problem is that you are using Typhoeus as your HTTP client, but hooking into FakeWeb, which only provides support for Net::HTTP. VCR can hook directly into Typhoeus (since it provides good public APIs for doing so) if you configure it:

VCR.configure do |vcr|
  vcr.hook_into :typhoeus
end

The hook_into docs list all the options and which hooks work with which HTTP clients. If you have any suggestions for improving the documentation to prevent others from having this confusion, please let me know.

Myron Marston
  • 21,452
  • 5
  • 64
  • 63
  • AH, that makes a ton of sense. For some reason, `hook_into` implied that VCR would require and use the facilities of :webmock (or :fakeweb or whatever) regardless of which http client was being used outside of the spec suite. At any rate, I've created a pull request at https://github.com/vcr/vcr/pull/228 as a suggestion on how to make it more clear (at least to me). Thanks for the quick reply! – brycemcd Dec 03 '12 at 00:24