【问题标题】:`require': cannot load such file -- capybara/rspec (LoadError)`require': 无法加载此类文件 -- capybara/rspec (LoadError)
【发布时间】:2012-11-27 09:49:37
【问题描述】:

我尝试测试我的项目。它以前工作过,我不知道每当我输入bundle exec rspec spec/ 时我做了什么,它说cannot load such file -- capybara/rspec (LoadError)。作为新手,我需要一个建议,哪个适合在 ruby​​ on rails 中测试我的 MVC。

Gemfile:
------------

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
  gem 'minitest'
  gem 'capybara', '1.1.2'
  gem 'rb-inotify', '0.8.8'
  gem 'libnotify', '0.5.9'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'spork-testunit'
  gem 'guard-test'
  gem 'ruby-prof'
  gem 'factory_girl_rails', '1.4.0' 
  if RUBY_PLATFORM =~ /linux/
    gem 'capybara-webkit'
  end
  gem 'launchy'
end

group :development, :test do
  gem 'rspec-rails', '2.10.0'
  gem 'guard-rspec', '0.5.5'
end

spec_helper:

require 'rubygems'
#require 'factory_girl'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'


  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rspec'
  require 'capybara/rails'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr
  config.mock_with :rspec

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = false

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  #Capybara.default_driver = :selenium
  Capybara.javascript_driver = :webkit
end

错误:

/home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- capybara/rspec (LoadError)
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
        from /home/IN4SYSTEMS/sri.kalai/Documents/promaster/spec/spec_helper.rb:11:in `<top (required)>'
        from /home/IN4SYSTEMS/sri.kalai/Documents/promaster/spec/helpers/loc/epcs_helper_spec.rb:1:in `require'
        from /home/IN4SYSTEMS/sri.kalai/Documents/promaster/spec/helpers/loc/epcs_helper_spec.rb:1:in `<top (required)>'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:66:in `rescue in run'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:62:in `run'
        from /home/IN4SYSTEMS/sri.kalai/Desktop/gems/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

提前致谢!!!

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 rspec


    【解决方案1】:

    我希望您确实安装了所有必需的 gem?使用bundle install 顺便说一句,您是否更改了 Gemfile,在这种情况下,您将需要使用 bundle install 安装 Gems。

    您可以查看gem list提供的宝石列表

    关于问题的第二部分,使用哪个测试 API。这是选择的问题。您可以坚持使用rpsec,如果您发现它没有达到您的预期,请注意更改。

    【讨论】:

    • 嗨,谢谢。我用错误列表更新了问题。我做了捆绑安装。但仍然没有运气。
    • gem list 显示水豚上市了吗?如果没有,请尝试手动添加并检查它是否有效。
    • 它显示了水豚 (1.1.2) 和水豚 webkit (0.12.1) 在 gem 列表中
    【解决方案2】:

    尝试gem query --local 看看capybara-screenshot 是否出现在您的已安装gem 列表中。 (出于某种原因,这为我呈现了与 gem list 不同的列表。)

    如果您没有看到,请尝试gem install capybara-screenshot。它不包含在 capybara 的安装中,因此仅在您的 gem 列表中看到 capybara 是不够的!

    【讨论】:

      【解决方案3】:

      我今天遇到了同样的问题,我通过以下方式解决了它:

      • 文件spec_helper.rb中的注释 下一个生 require 'capybara/rspec' require 'capybara/rails',

      • 移除 /usr/local/rvm/gems/ruby-1.9.3-p327@olha/gems/capybara-webkit-1.1.0 从我的硬盘空间。

      【讨论】:

      • 能否请您扩展此答案以便其他人使用?
      猜你喜欢
      • 1970-01-01
      • 2017-08-14
      • 2014-05-27
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多