我正在處理一個讓我很煩的問題。出於某種原因,我無法在本地機器上啓動rspec。我嘗試了各種方法來安裝和運行它,但都沒有工作。 我使用捆綁器在git存儲庫上運行Ruby on Rails 2.3.5和Ruby 1.8.7。Rspec無法在ubuntu上運行
首先,我嘗試安裝rspec作爲寶石。爲此,我增加了以下條目我的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中創建了一個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
當使用
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安裝rspec for rails 3,而我需要rspec for rails 2.3.5。但我已經嘗試了很多工作。無論如何,我想這是錯誤的方式,所以我最終停止了尋找最後一個錯誤信息的確切原因。
有沒有人有猜測我還有什麼可以嘗試?或者,也許我應該改變?
你嘗試'束EXEC rspec'(而不是'捆綁高管spec')? – cdesrosiers
感謝您的提示。我嘗試了'spec'和'rspec'。使用從Ubuntu源碼安裝的ruby-rspec-core,它可以運行,但並不真正執行給定的規範。當我輸入'bundle exec rspec'時,結果如下所示:'}排除了所有內容? 在0.00003秒成品 0例,0 failures' –
而使用'包的exec rspec的規格/型號/ bookmark_spec.rb'給了我前面提到的錯誤... –