I'm attempting to use VCR 2.0.0 outside of Rails.
VCR seems to create the vcr_cassettes
directory perfectly when I run the specs. However, the tests seem to be still hitting the network and there are never any yaml cassettes to be found in the cassette directory.
Any ideas what I'm doing wrong?
Here is an example of me running the specs in question:
rm -r spec/fixtures/vcr_cassettes
rspec spec/lib/availability_checkers/net_checker_spec.rb
...*
Finished in 1.83 seconds
3 examples, 0 failures, 0 pending
ls spec/fixtures/vcr_cassettes
=> # created but empty
I have a spec/support/vcr_helper.rb
:
require "vcr"
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
end
And I have a spec file under spec/lib/availability_checkers/net_checker_spec.rb
:
require "availability_checkers/net_checker'
require "support/vcr_helper"
describe NetChecker, "check" do
it "should return false if the domain is unavailable" do
VCR.use_cassette("unavailable_domain") do
NetChecker.check("apple.com").should be_false
end
end
end
And just incase you're interested, here's the method being tested in lib/availability_checkers/net_checker.rb
:
require "whois"
class NetChecker
def check(host)
# this part hits the network
return Whois.available?(host)
rescue Whois::Error => e
return nil
end
end
I believe your problem is that VCR only records and plays back HTTP connections, while the Whois gem uses TCPSocket and not any of the http libraries VCR knows how to proxy.