【问题标题】:Rspec fails to run on ubuntuRspec 无法在 ubuntu 上运行
【发布时间】:2012-09-27 20:25:26
【问题描述】:

我正在处理一个困扰我很久的问题。出于某种原因,我无法在本地机器上启动 rspec。我尝试了各种方法来安装和运行它,但都没有奏效。 我正在使用 bundler 在 git 存储库上运行 Ruby on Rails 2.3.5 和 Ruby 1.8.7。

首先,我尝试将 rspec 安装为 gem。为此,我在我的 Gemfile 中添加了以下条目:

group :test do
  gem 'rspec', '=1.3.0'
  gem "rspec-rails", "=1.3.2"
end
...
group :cucumber do
  gem 'rspec', '=1.3.0'
  gem "rspec-rails", "=1.3.2"  
end

当我检查时

宝石清单

我来看看

*** LOCAL GEMS ***
(...)
rspec (1.3.0)
rspec-rails (1.3.2)

所以,它一定在那里。然后我在 /spec/model/bookmark_step.rb 中创建了一个规范文件。但是当我尝试用

运行它时

rspec 规格/模型/bookmark_spec.rb

我明白了

The program 'rspec' is currently not installed.  You can install it by typing:
sudo apt-get install ruby-rspec-core

使用时

捆绑执行规范

我明白了

捆绑器:找不到命令:rspec 使用 bundle install 安装缺少的 gem 可执行文件

好的,到目前为止很糟糕。让我们试试别的。为什么不从 ubuntu 源安装(我正在使用 Ubuntu 12.04):

sudo apt-get install ruby​​-rspec-core

建议的包: 红宝石-rspec 将安装以下新软件包: ruby-rspec-核心 0 个已升级,1 个新安装,0 个要移除,73 个未升级。

好的,让我们输入

rspec 规格/模型/bookmark_spec.rb

猜猜我得到了什么......

/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant RSpec::Core::Formatters (NameError)
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
from /var/lib/gems/1.8/gems/rspec_spinner-2.0.0/lib/rspec_spinner/base.rb:12
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
from /var/lib/gems/1.8/gems/rspec_spinner-2.0.0/lib/rspec_spinner.rb:4
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `each'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `each'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler.rb:119:in `require'
from (...) Workspace/config/boot.rb:116:in `load_gems'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:164:in `process'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
from (...)  Workspace/config/environment.rb:28
from (...)  Workspace/spec/model/../spec_helper.rb:4:in `require'
from (...)  Workspace/spec/model/../spec_helper.rb:4
from (...)  Workspace/spec/model/bookmark_spec.rb:2:in `require'
from (...)  Workspace/spec/model/bookmark_spec.rb:2
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `map'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/command_line.rb:18:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:55:in `run_in_process'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:46:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:10:in `autorun'
from /usr/bin/rspec:4

好的,最后一件事可能是版本不匹配。我猜ubuntu为rails 3安装了rspec,而我需要为rails 2.3.5安装rspec。但我已经尝试了很多让它发挥作用。无论如何,我想那是错误的方式,所以我最终停止寻找最后一条错误消息的确切原因。

有人猜我还能尝试什么吗?或者也许我应该改变什么?

【问题讨论】:

  • 你试过bundle exec rspec(而不是bundle exec spec)吗?
  • 感谢您的提示。我尝试了specrspec。从 Ubuntu 源安装 ruby​​-rspec-core 后,它可以运行,但并没有真正执行给定的规范。当我输入bundle exec rspec 时,结果如下所示:<Proc:0xb731cd80@/usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:50>} is excluding everything? Finished in 0.00003 seconds 0 examples, 0 failures
  • 而使用bundle exec rspec spec/model/bookmark_spec.rb 会给我前面提到的错误...

标签: ruby-on-rails rspec ubuntu-12.04 rspec-rails


【解决方案1】:

出于某种原因,我注意到在 Ubuntu 上加载环境的时间不够早,无法触发捆绑程序加载测试组 gem。我还没有找出根本原因,但是像这样运行我的测试是可行的:

RAILS_ENV=test bundle exec rspec

【讨论】:

    【解决方案2】:

    我们一直在为我们的 rails 2.3.14 应用程序使用以下内容。我想它也应该适用于 2.3.5...

    group :development, :test do
      gem "rspec-rails", "1.3.4"
      gem "steak"
      gem "factory_girl", "2.6.4"
      gem "database_cleaner"
    end
    
    group :test do
      gem "mocha"
      gem "capybara", "~> 0.3.9"
    end
    

    【讨论】:

    • 好的,谢谢您的回答。我也试过那个。结果是以下错误:/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in load_missing_constant': uninitialized constant RSpec::Core::Formatters (NameError) from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb :80:在const_missing' (...)。但是,它肯定安装在我的系统上。我检查了gem listrspec (1.3.1, 1.3.0) rspec-rails (1.3.4, 1.3.2) 这似乎不是版本问题,而是安装问题...
    猜你喜欢
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 2017-03-14
    相关资源
    最近更新 更多