Rails 以外でVCR 2.0.0を使おうとしています。
仕様を実行すると、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
:
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
興味がある場合に備えて、 でテストされているメソッドを次に示します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