rspec错误(无法加载此类文件)

时间:2015-02-13 15:58:02

标签: ruby-on-rails ruby rspec

我正在做Rails教程(Michael Hartl)。在3.2.1部分,我按照所有说明操作并运行了rspec测试: 捆绑exec rspec spec / requests / static_pages_spec.rb 。正如教程所说,我试图为主页运行单元测试。使用此命令生成测试: rails生成integration_test static_pages ,然后我再次编辑它,如教程所述(下面的代码 static_pages_spec.rb )。我使用rubymine IDE。版本不同于教程cus Railsinstaller for Windows改变了ruby和rails的版本。似乎Windows没有rvm。所以我在gemfile中更改了版本。之前没有问题。 以下是作者对此命令的说法:

  

为了实际运行测试,我们有几个选项,包括3.6节中讨论的一些方便但相当高级的工具。现在,我们将在命令行中使用rspec命令(使用bundle exec执行以确保RSpec在我们的Gemfile指定的环境中运行)

我得到了回应:

D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/Win32/Console
.rb:12:in `require': cannot load such file -- 2.1/Console_ext (LoadError)
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
Win32/Console.rb:12:in `rescue in <top (required)>'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
Win32/Console.rb:8:in `<top (required)>'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
Win32/Console/ANSI.rb:13:in `require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
Win32/Console/ANSI.rb:13:in `<top (required)>'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
win32console.rb:1:in `require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/win32console-1.3.2-x86-mingw32/lib/
win32console.rb:1:in `<top (required)>'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:76:in `require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:76:in `block (2 levels) in require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:72:in `each'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:72:in `block in require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:61:in `each'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler/runtime.r
b:61:in `require'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.7.7/lib/bundler.rb:133:in
 `require'
        from D:/Programming/Projects/Ruby/Rails/sample_app/config/application.rb:14:in `<top (required)>'
        from D:/Programming/Projects/Ruby/Rails/sample_app/config/environment.rb:2:in `require'
        from D:/Programming/Projects/Ruby/Rails/sample_app/config/environment.rb:2:in `<top (required)>'
        from D:/Programming/Projects/Ruby/Rails/sample_app/spec/spec_helper.rb:3:in `require'
        from D:/Programming/Projects/Ruby/Rails/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
        from D:/Programming/Projects/Ruby/Rails/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
        from D:/Programming/Projects/Ruby/Rails/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/co
nfiguration.rb:819:in `load'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/co
nfiguration.rb:819:in `block in load_spec_files'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/co
nfiguration.rb:819:in `each'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/co
nfiguration.rb:819:in `load_spec_files'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/co
mmand_line.rb:22:in `run'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/ru
nner.rb:80:in `run'
        from D:/Programming/Programs/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/ru
nner.rb:17:in `block in autorun'

static_pages_spec.rb

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

我的宝石文件

source 'https://rubygems.org'

ruby '2.1.5'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.1.8'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'

group :development, :test do
  gem 'sqlite3'
  gem 'rspec-rails', '2.13.1'
  # The following optional lines are part of the advanced setup.
  # gem 'guard-rspec', '2.5.0'
  # gem 'spork-rails', '4.0.0'
  # gem 'guard-spork', '1.5.0'
  # gem 'childprocess', '0.3.6'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.0'
  gem 'cucumber-rails', '1.4.0', :require => false
  gem 'database_cleaner', github: 'bmabey/database_cleaner'

  # Uncomment this line on OS X.
  # gem 'growl', '1.0.3'

  # Uncomment these lines on Linux.
  # gem 'libnotify', '0.8.0'

  # Uncomment these lines on Windows.
  gem 'rb-notifu', '0.0.4'
  gem 'win32console', '1.3.2'
  gem 'wdm', '0.1.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'coffee-script-source', '1.8.0'

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

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]

平台:Windows

似乎有 win32console gem的东西。但我不知道到底是什么。

P.S。很抱歉发布的信息不足。我对所发生的事情了解甚少。

1 个答案:

答案 0 :(得分:1)

我发现 win32Console 是一个旧的gem,在Ruby 2.0中不需要,所以我从gemfile中删除了它。然后我收到了这条消息:

  

警告:您应该要求'minitest / autorun'。   警告:或者在'require'minitest / autorun“'

之前添加'gem”minitest“'

所以我添加了minitest gem并且它有效。谢谢大家!