9

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

OS : Ubuntu 13.04

解決策を探していますが、見つかりませんでした。私は Ruby on Rails と Web 開発の初心者であることを覚えておいてください。

4

3 に答える 3

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 を更新する必要があります

于 2013-09-01T20:23:04.670 に答える
4

最近同じ問題が発生し、宝石のバージョンを変更するだけでした

gem 'selenium-webdriver', '2.0.0'

最後の 1 つに:

gem 'selenium-webdriver', '2.35.1'

それはそれを修正しました!rubyzip gem をインストールする必要はありませんでした。

于 2013-09-12T20:56:27.917 に答える
1

変化する

gem 'selenium-webdriver', '2.0.0'

gem 'selenium-webdriver'

あなたのGemfileで

于 2013-09-04T16:01:01.480 に答える