我正在处理一段困扰我很久的问题。出于某种原因,我无法在本地计算机上启动rspec。我已经尝试了各种方法来安装和运行它,但它们都没有工作。 我正在使用bundler在git存储库上使用Ruby 1.8.7运行Ruby on Rails 2.3.5。
首先,我尝试将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中创建了一个spec文件。但是当我尝试用
运行它时rspec spec / model / bookmark_spec.rb
我得到了
The program 'rspec' is currently not installed. You can install it by typing:
sudo apt-get install ruby-rspec-core
使用时
捆绑exec规范
我得到了
bundler:找不到命令:rspec 使用
安装缺少的gem可执行文件bundle install
好的,到目前为止一直很糟糕。我们试试别的吧。为什么不从ubuntu源安装(我正在使用Ubuntu 12.04):
sudo apt-get install ruby-rspec-core
推荐套餐: 红宝石的RSpec 将安装以下新包: 红宝石rspec的核心 0升级,1新安装,0删除,73未升级。
好的,让我们滚动
rspec spec / model / 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,而我需要rspec for rails 2.3.5。但我已经尝试了很多工作。无论如何,我认为这是错误的方式,所以我最终停止寻找最后一条错误消息的确切原因。
有没有人猜到我还能尝试什么?或者也许我应该改变一些事情?
答案 0 :(得分:2)
出于某种原因,我在Ubuntu上注意到环境没有及早加载以触发捆绑器加载测试组gem。我还没有想出根本原因,但运行我的测试工作:
RAILS_ENV=test bundle exec rspec
答案 1 :(得分: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