Reputation: 4039
I'm trying to learn RoR following this tutorial and I'm currently in chapter 3. The tutorial works fine if I follow it line-by-line. However, the commands used in the tutorial suppress generation of default tests. When I try to keep them and possibly use them in my project, I always hit a wall somewhere.
Could you please tell me what I'm doing wrong?
$ rails new myproject
$ cd myproject/
$ echo "gem 'rspec'" >> Gemfile
$ echo "gem 'rspec-rails'" >> Gemfile
$ echo "gem 'capybara'" >> Gemfile
$ bundle install
$ bundle --binstubs
$ rails generate rspec:install
$ rails generate controller StaticPages home help about
Then I edit the spec/views/static_pages/home.html.erb_spec.rb
file, to test whether capybara works:
require 'spec_helper'
#require 'capybara'
#require 'capybara/rails'
#require 'capybara/rspec'
describe "static_pages/home.html.erb" do
it 'should have a right title' do
visit '/static_pages/home'
page.should have_selector('title', :text => 'Home')
end
end
Running bin/rspec
at this point, obviously, ends up with a failure. Well, a failure could have been expected. The reason for one of these failures is more alarming, though:
1) static_pages/home.html.erb should have a right title
Failure/Error: visit '/static_pages/home'
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_5:0x00000003dfd268>
# ./spec/views/static_pages/home.html.erb_spec.rb:7:in `block (2 levels) in <top (required)>'
The visit
method, which AFAIK is part of Capybara, has not been found. Uncommenting the three extra requires in home.html.erb_spec.rb
does not change anything in the result.
Any ideas what I'm doing wrong? Or what I should do better?
Rails version: 3.2.6
Upvotes: 4
Views: 599