无法使用VCR记录Whois请求?
问题描述:
我试图在Rails之外使用VCR 2.0.0。无法使用VCR记录Whois请求?
当我运行规格时,VCR似乎完美地创建了vcr_cassettes
目录。但是,这些测试似乎仍然在网络中,并且在卡匣目录中找不到任何yaml卡匣。
任何想法我做错了什么?
这里是运行有问题的规范我的一个例子:
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
我有一个spec/support/vcr_helper.rb
:
require "vcr"
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
end
而且我有spec/lib/availability_checkers/net_checker_spec.rb
下一个spec文件:
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
只要你有兴趣,这里是在测试的方法:
require "whois"
class NetChecker
def check(host)
# this part hits the network
return Whois.available?(host)
rescue Whois::Error => e
return nil
end
end
答
我相信你的问题是VCR only records and plays back HTTP connections,而Whois gem uses TCPSocket,而不是任何HTTP库VCR知道如何代理。
对我来说听起来很合适。谢谢。 – 2012-03-18 23:17:50
您可能只需在NetChecker的Whois合作者处发一个简单的期望,以便将测试与网络隔离开来,例如:Whois.expects(:available?)。('apple.com')。returns(false)' – dbenhur 2012-03-18 23:32:04
Yeah looks就像我将不得不这样做。只是当我在系统边缘测试时,我喜欢进一步探索。 – 2012-03-18 23:47:03