简体   繁体   English

`require':无法加载这样的文件 - capybara / rspec(LoadError)

[英]`require': cannot load such file — capybara/rspec (LoadError)

I tried to test my project. 我试着测试我的项目。 It was working before and I don't know what i did to whenever i type bundle exec rspec spec/ it says cannot load such file -- capybara/rspec (LoadError) . 它以前工作,我不知道我做什么,每当我键入bundle exec rspec spec/它说cannot load such file -- capybara/rspec (LoadError) And Please I need an advice to which one is good for testing my MVC in ruby on rails as a newbie. 并且我需要一个建议,哪个有利于测试我的MVC在ruby轨道作为新手。

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: 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

Error: 错误:

/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'

Thanks in advance!!! 提前致谢!!!

I hope you did install all required gems? 我希望你安装了所有必需的宝石? Using bundle install BTW did you change Gemfile, in that case you would be required to install Gems using bundle install. 使用bundle install BTW你改变了Gemfile,在这种情况下你需要使用bundle install来安装Gems。

You could check list of gems available by gem list 您可以查看gem list可用的gem list

Regarding second part of the question, which testing API to use. 关于问题的第二部分,使用哪种测试API。 It is matter of choice. 这是选择的问题。 You could stick with rpsec and if you find it falls short of your expectation, then look out for change. 您可以坚持使用rpsec ,如果您发现它达不到您的期望,那么请注意改变。

Try gem query --local to see if capybara-screenshot appears in your list of installed gems. 尝试使用gem query --local查看gem query --local capybara-screenshot出现在已安装宝石的列表中。 (For some reason, this rendered a different list than gem list for me.) (出于某种原因,这为我提供了不同于gem list 。)

If you don't see it, then try gem install capybara-screenshot . 如果你没有看到它,那么试试gem install capybara-screenshot It is not included in the installation of capybara , so seeing capybara in your list of gems alone is not sufficient! 它不包含在capybara的安装中,因此仅仅在宝石列表中看到capybara是不够的!

I had the same problem today and I fixed it in the following way: 我今天遇到了同样的问题,我通过以下方式修复它:

  • Comment in file spec_helper.rb next raws require 'capybara/rspec' require 'capybara/rails' , 在文件spec_helper.rb注释下一个spec_helper.rb require 'capybara/rspec' spec_helper.rb require 'capybara/rspec' require 'capybara/rails'

  • Remove /usr/local/rvm/gems/ruby-1.9.3-p327@olha/gems/capybara-webkit-1.1.0 from my HDD space. 从我的硬盘空间中删除/usr/local/rvm/gems/ruby-1.9.3-p327@olha/gems/capybara-webkit-1.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 `require&#39;:无法加载此类文件-./controllers/ <controller> (LoadError)与Rspec - `require': cannot load such file — ./controllers/<controller> (LoadError) with Rspec Rails Rspec `require': 无法加载此类文件 -- rails_helper (LoadError) - Rails Rspec `require': cannot load such file -- rails_helper (LoadError) 尝试运行 rspec 时出错:`require&#39;: 无法加载此类文件 — rails_helper (LoadError) - Error when trying to run rspec: `require': cannot load such file — rails_helper (LoadError) &#39;require&#39;:无法加载此类文件&#39;gem&#39;(LoadError) - 'require': cannot load such file 'gem' (LoadError) `require&#39;:无法加载此类文件-捆绑程序/安装程序(LoadError) - `require': cannot load such file — bundler/setup (LoadError) `require&#39;:无法加载此类文件-赛​​璐ul /当前(LoadError) - `require': cannot load such file — celluloid/current (LoadError) `require&#39;:无法加载此类文件-rails / all(LoadError) - `require': cannot load such file — rails/all (LoadError) `require&#39;:无法加载此类文件-simplecov(LoadError) - `require': cannot load such file — simplecov (LoadError) `require&#39;:无法加载此类文件-cancan(LoadError) - `require': cannot load such file — cancan (LoadError) `require&#39;:无法加载此类文件-mysql(LoadError) - `require': cannot load such file — mysql(LoadError)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM