gpt4 book ai didi

ruby-on-rails - Rspec 无法在 ubuntu 上运行

转载 作者:行者123 更新时间:2023-12-02 02:11:09 25 4
gpt4 key购买 nike

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

当我检查

gem list

我看到了

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

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

运行它时

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

使用时

bundle exec spec

我明白了

bundler: command not found: rspec Install missing gem executables with bundle install

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

sudo apt-get install ruby-rspec-core

Suggested packages: ruby-rspec The following NEW packages will be installed: ruby-rspec-core 0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded.

好的,让我们开始输入

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,而我需要为 rails 2.3.5 安装 rspec。但我已经尝试了很多来让它发挥作用。无论如何,我想那是错误的方式,所以我最终停止寻找最后一条错误消息的确切原因。

有没有人猜到我还能尝试什么?或者我应该改变什么?

最佳答案

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

RAILS_ENV=test bundle exec rspec

关于ruby-on-rails - Rspec 无法在 ubuntu 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12767278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com