3

我正在处理一个困扰我很久的问题。出于某种原因,我无法在本地机器上启动 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

使用时

捆绑执行规范

我明白了

bundler:找不到命令:rspec 安装缺少的 gem 可执行文件bundle install

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

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

建议的软件包:ruby-rspec 将安装以下新软件包:ruby-rspec-core 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。但我已经尝试了很多让它发挥作用。无论如何,我想那是错误的方式,所以我最终停止寻找最后一条错误消息的确切原因。

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

4

2 回答 2

2

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

RAILS_ENV=test bundle exec rspec

于 2015-02-26T06:23:34.683 回答
0

我们一直在为我们的 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
于 2012-10-07T15:14:05.777 回答