我在做Railscast #291 Testing with VCR (Pro)。
我想将rspec与vcr
一起使用。没有vcr的测试通过了这段代码。
# spec/requests/zip_code_lookup_spec.rb
require "spec_helper"
describe "ZipCodeLookup" do
it "show Beverly Hills given 90210" do
visit root_path
fill_in "zip_code", with: "90210"
click_on "Lookup"
page.should have_content("Beverly Hills")
end
end
正如教程我把代码放在VCR.use_cassette
这样:
require "spec_helper"
describe "ZipCodeLookup" do
it "show Beverly Hills given 90210" do
VCR.use_cassette "zip_code/90210" do
visit root_path
fill_in "zip_code", with: "90210"
click_on "Lookup"
page.should have_content("Beverly Hills")
end
end
end
并创建了这个文件:
# spec/support/vcr.rb
VCR.configure do |c|
c.cassette_library_dir = Rails.root.join("spec", "vcr")
c.stub_with :fakeweb
end
根据教程,rspec测试应该通过这个,但它失败并出现此错误:
1) ZipCodeLookup show Beverly Hills given 90210
Failure/Error: click_on "Lookup"
Zlib::GzipFile::Error:
not in gzip format
# ./app/models/zip_code.rb:6:in `initialize'
# ./app/controllers/zip_code_lookup_controller.rb:3:in `new'
# ./app/controllers/zip_code_lookup_controller.rb:3:in `index'
# ./spec/requests/zip_code_lookup_spec.rb:8:in `block (3 levels) in <top (required)>'
# ./spec/requests/zip_code_lookup_spec.rb:5:in `block (2 levels) in <top (required)>'
我不知道为什么gzip
出现在这里,而不是在其余的rails项目中。
我该如何解决这个问题?
答案 0 :(得分:0)
刚出现同样的问题: fakeweb gem现在是deprecated in VCR,请使用 webmock
在你的Gemfile中,替换
gem 'fakeweb'
通过
gem 'webmock'
重新捆绑,你应该排序