2013-12-14 39 views
3

我正在關注Michael Hartl的Ruby on Rails 4書,並且找不到spec/spec_helper.rb。這是他的書http://ruby.railstutorial.org/ruby-on-rails-tutorial-book的鏈接,我正在開發第3章測試驅動開發部分。RSpec - 無法找到規範/ spec_helper.rb

我跑這個代碼調用RSpec的和static_pages_spec.rb

$ rails generate integration_test static_pages  
invoke rspec  
create spec/requests/static_pages_spec.rb 

這個我需要的水豚DSL添加到RSpec的幫助文件之後。我的問題是我找不到或打開spec/spec_helper.rb。我試過$subl spec/spec_helper.rb,但它只打開了一個空的文本編輯器文件。

添加以下內容以便我的Gemfile的RSpec的和TDD:

group :development, :test do 
gem 'sqlite3', '1.3.8' 
gem 'rspec-rails', '2.13.1' 
end 

group :test do 
gem 'selenium-webdriver', '2.35.1' 
gem 'capybara', '2.1.0' 
end 

冉:

$ bundle install --without production 
$ bundle update 
$ bundle install 
$ rails generate rspec:install 
$ rails generate integration_test static_pages 

這一點後,我猜想打開spec/sepc_helper.rb並添加CapybaraDSL並運行此$ bundle exec rspec spec/requests/static_pages_spec.rb。因爲我無法找到spec_helper.rb,我只是跑它在我的終端上,看看發生了什麼,得到了以下錯誤:

in `require': cannot load such file -- spec_helper (LoadError) 

我不知道爲什麼我找不到spec_helper。我閱讀了其他教程,看起來像spec_helper文件在加載RSpec時自動形成。

+1

如果有用的話。 :) – SergeyKutsko

回答

4

檢查的Gemfile爲:

group :development, :test do 
    gem 'rspec-rails', '~> 3.0.0.beta' 
end 

運行在控制檯bundle install命令:

rails generate rspec:install

嘗試在bash在項目文件夾:

find -name spec_helper.rb 

有一個完整的引用Rspec使用機智h rails:https://github.com/rspec/rspec-rails

1

確保您已安裝rspec gem。您可以通過聲明它在你的Gemfile

做到這一點

https://github.com/rspec/rspec-rails

在Gemfile中

group :development, :test do 
    gem 'rspec-rails', '~> 3.0.0.beta' 
end 

bundle install

bundle exec rails generate rspec:install

這些措施將產生什麼需要運行rspec的。

1

可能值得一提的是,偶爾我會嘗試在根目錄以外的文件夾中運行rspec,這是彈出的錯誤。我似乎記得,這可以以某種方式修改,但不知道如何。

5

仔細檢查您是否從root rails目錄運行rspec spec/,而不是從spec目錄中運行。

相關問題