簡體   English   中英

ruby on rails rspec錯誤

[英]ruby on rails rspec error

我正在閱讀“通過示例學習Rails”一書,我正在嘗試運行測試。 出於某種原因,我無法讓rspec正常工作。

如果我按照他的指示運行rspec spec/命令,我會收到以下錯誤:

$ rspec spec/
/home/desktop/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup': 
You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4. 
Using bundle exec may solve this. (Gem::LoadError)

奇怪的是我的Gemfile沒有指定版本 -

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat'
end

如果我按照錯誤消息的建議並使用bundle exec rspec spec/然后前兩個測試通過 - 但是我們在教程中構建的新“about”頁面失敗並出現以下錯誤,盡管據我所知我構建的頁面(以及控制器操作等)完全符合它們的要求:

Failures:

  1) PagesController GET 'about' should be successful
     Failure/Error: response.should_be_success
     NoMethodError:
       undefined method `should_be_success' for #<ActionController::TestResponse:0x00000003539438>
     # ./spec/controllers/pages_controller_spec.rb:23:in `block (3 levels) in <top (required)>'

Finished in 0.10861 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' should be successful

我是一個非常有經驗的程序員,但是我遇到了沖突的寶石版本和使用Rails完成所有不同任務的一百種不同方法的無窮無盡的問題(例如“使用RVM”,“不要使用RVM”,“安裝”寶石使用sudo“,”不要使用sudo“等安裝寶石)

我的開發機器正在運行ubuntu linux。

感謝您的幫助 - 請解釋一下,如果您在Ruby noob語言中做錯了!

運行bundle exec是正確的,並且是必需的,因為您安裝了更新版本的gem,而不是Gemfile.lock中指定的版本。 使用bundle exec會覆蓋加載路徑,只會加載Gemfile.lock中指定的gem。 (您可能會發現將別名bundle exec為更短的內容非常方便。)

第二個問題的答案就在錯誤消息中:

undefined method `should_be_success'

它應該是should be_success

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM