我有一个非常简单的module我正在使用VCR gem测试Ruby.
我根据文档配置了录像机,但似乎无法在录像带目录中录制录像带.我甚至将盒式磁带目录的权限更改为777以防万一.真奇怪的是,我已经完全删除了磁带目录,运行规范,然后创建了一个新的磁带目录.
我正在使用Typhoeus0.4.2 Hydra.我此刻无法升级Typhoeus.
相关代码:
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
...
Run Code Online (Sandbox Code Playgroud)
我不知道为什么没有写入磁带.
问题是您正在使用TyphoeusHTTP客户端,但是FakeWeb只是提供支持Net::HTTP.如果您配置它,VCR可以直接挂钩到Typhoeus(因为它提供了良好的公共API):
VCR.configure do |vcr|
vcr.hook_into :typhoeus
end
Run Code Online (Sandbox Code Playgroud)
该hook_into文档列出所有的选项和挂钩工作与HTTP客户端.如果您有任何改进文档的建议,以防止其他人混淆,请告诉我.