0
我試圖在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
對我來說聽起來很合適。謝謝。 – 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