Reputation: 1028
I'm following Michael Hartl's Ruby on Rails 4 book and can't find the spec/spec_helper.rb
. This is the link to his book http://ruby.railstutorial.org/ruby-on-rails-tutorial-book and I'm working on Chapter 3 Test driven development section.
I ran this code to invoked RSpec and static_pages_spec.rb
$ rails generate integration_test static_pages
invoke rspec
create spec/requests/static_pages_spec.rb
After this I need to add the Capybara DSL to the RSpec helper file.
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
PROBLEM: my problem is that I can't find or open spec/spec_helper.rb
. I've tried $subl spec/spec_helper.rb
but it only opened an empty text editor file.
Added Followings to my Gemfile for RSpec and 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
Ran:
$ bundle install --without production
$ bundle update
$ bundle install
$ rails generate rspec:install
$ rails generate integration_test static_pages
After this point, I'm suppose to open spec/sepc_helper.rb
and add the CapybaraDSL
and run this $ bundle exec rspec spec/requests/static_pages_spec.rb
. Since I couldn't find the spec_helper.rb
, I just ran it on my terminal to see what happens and got following error:
in `require': cannot load such file -- spec_helper (LoadError)
I'm not sure why I can't find spec_helper. I read the other tutorials and it seems like spec_helper file automatically forms when they load RSpec.
Upvotes: 3
Views: 10579
Reputation: 3421
Double check that you are running rspec spec/
from the root rails directory and not from within the spec directory.
Upvotes: 5
Reputation: 1394
It may be worth mentioning that occasionally I try to run rspec in a folder other than the root directory and this is the error that pops up. I seem to recall that this can be modified somehow, but not sure how.
Upvotes: 1
Reputation: 1814
Make sure you have the rspec gem installed. You can do this by declaring it in your Gemfile
https://github.com/rspec/rspec-rails
In Gemfile
group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta'
end
bundle install
bundle exec rails generate rspec:install
Those steps will create what's needed to run rspec.
Upvotes: 1
Reputation: 697
check Gemfile for:
group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta'
end
run bundle install
command at console:
after rails generate rspec:install
try in a bash at project folder:
find -name spec_helper.rb
there is a complete referece for Rspec
usage with rails: https://github.com/rspec/rspec-rails
Upvotes: 4