【发布时间】:2013-11-30 07:03:09
【问题描述】:
我在做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 项目的其余部分中。
我该如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails rspec