我正在关注Michael Hartl的Ruby on Rails 4书,但找不到spec/spec_helper.rb
.这是他的书http://ruby.railstutorial.org/ruby-on-rails-tutorial-book的链接,我正在研究第3章测试驱动开发部分.
我运行此代码来调用RSpec和static_pages_spec.rb
$ rails generate integration_test static_pages invoke rspec create spec/requests/static_pages_spec.rb
在此之后,我需要将Capybara DSL添加到RSpec帮助文件中.
spec/spec_helper.rb # This file is copied to spec/ when you run 'rails generate spec:install' … RSpec.configure do |config| . . . config.include Capybara::DSL end
问题:我的问题是我无法找到或打开spec/spec_helper.rb
.我试过$subl spec/spec_helper.rb
但它只打开一个空的文本编辑器文件.
为RSpec和TDD添加了我的Gemfile的跟随:
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时会自动形成.
仔细检查您是rspec spec/
从root rails目录运行,而不是从spec目录中运行.