来自Hartl教程的bundle exec rspec spec / requests / static_pages_spec.rb无效

时间:2013-09-01 06:49:23

标签: ruby-on-rails ruby rspec

我正在关注Michael Hartl的ruby on rails教程来测试示例应用程序(3.2.1测试驱动开发),但是在输入bundle exec rspec spec/requests/static_pages_spec.rb之后我收到了以下错误

/home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `require': cannot load such file -- zip/zip (LoadError)
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common/zipper.rb:1:in `<top (required)>'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common.rb:9:in `require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver/common.rb:9:in `<top (required)>'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver.rb:29:in `require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium/webdriver.rb:29:in `<top (required)>'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium-webdriver.rb:1:in `require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib/selenium-webdriver.rb:1:in `<top (required)>'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
    from /home/rahul/Downloads/rails_projects/sample_app/config/application.rb:12:in `<top (required)>'
    from /home/rahul/Downloads/rails_projects/sample_app/config/environment.rb:2:in `require'
    from /home/rahul/Downloads/rails_projects/sample_app/config/environment.rb:2:in `<top (required)>'
    from /home/rahul/Downloads/rails_projects/sample_app/spec/spec_helper.rb:3:in `require'
    from /home/rahul/Downloads/rails_projects/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
    from /home/rahul/Downloads/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
    from /home/rahul/Downloads/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
    from /home/rahul/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

以下是spec/requests/static_pages_spec文件中的代码:

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Sample App' " do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end

  end

end

Gemfile

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'

group :development, :test do
  gem 'sqlite3', '1.3.7'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.0.0'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

routes.rb

SampleApp::Application.routes.draw do
  get "static_pages/home"
  get "static_pages/help"
end

操作系统:Ubuntu 13.04

我一直在寻找解决方案,但还没有找到解决方案。请记住,我是Ruby on Rails和Web开发的新手。

3 个答案:

答案 0 :(得分:13)

错误消息:

in `require': cannot load such file -- zip/zip (LoadError)

指的是一个名为“rubyzip”的缺失宝石。它应该由捆绑器和selenium-web驱动程序一起安装,但有时这些东西并不完美。在这种情况下,最新版本的“rubyzip”gem已经改变了库结构,因此不存在“zip / zip”。默认情况下,Bundler将安装最新版本,这就是安装时没有错误的原因,但是当您尝试运行项目时会出现错误,因为selenium-webdriver依赖项列表并不知道差异。

尝试将gem 'rubyzip', '< 1.0.0'添加到您的测试组,然后重新运行bundle install


此问题似乎是由rubyzip gem的更新引起的,请参阅https://github.com/rubyzip/rubyzip

selenium-webdriver gem可能需要更新以反映这些更改 - 我已经记录了一个问题:https://github.com/vertis/selenium-webdriver/issues/3

答案 1 :(得分:4)

我最近遇到了同样的问题,只是改变了宝石的版本

gem 'selenium-webdriver', '2.0.0'

到最后一个:

gem 'selenium-webdriver', '2.35.1'
它修好了!没有必要安装rubyzip gem。

答案 2 :(得分:1)

更改

gem 'selenium-webdriver', '2.0.0'

gem 'selenium-webdriver'
你的Gemfile中的