0
votes

I'm learning ruby on rails with the Ruby on Rails Tutorial book online, and I came across this exercise http://www.railstutorial.org/book/static_pages#code-capybara_dsl

I followed the instruction on adding

RSpec.configure do |config|
  config.include Capybara::DSL
end

to my spec_helper.rb, but now I am receiving the errors

uninitialized constant Capybara <NameError>

This is my current spec_helper.rb

require "spec_helper"

RSpec.configure do |config|
  config.include Capybara::DSL
end

describe "Static pages" do 
  describe "Home page" do 
    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end

describe "Help page" do

    it "should have the content 'Help'" do
      visit '/static_pages/help'
      expect(page).to have_content('Help')
    end
end

 describe "About page" do

     it "should have the content 'About Us'" do
      visit '/static_pages/about'
      expect(page).to have_content('About Us')
     end
  end
end

What am I doing wrong? did I install the gem incorrectly?

Edit: Not sure if this would help, but here is the failed examples output after I called $ bundle exec rspec spec/requests/static_pages_spec.rb

←[31mrspec ./spec/spec_helper.rb:7←[0m ←[36m# Static pages Home page should have
 the content 'Sample App'←[0m
←[31mrspec ./spec/spec_helper.rb:15←[0m ←[36m# Static pages Help page should hav
e the content 'Help'←[0m
←[31mrspec ./spec/spec_helper.rb:23←[0m ←[36m# Static pages About page should ha
ve the content 'About Us'←[0m
←[31mrspec ./spec/requests/static_pages_spec.rb:5←[0m ←[36m# StaticPages GET /st
atic_pages works! (now write some real specs)←[0m
1
Could you verify if the rspec gem is specified in your Gemfile? - evedovelli
I currently have gem 'rspec-rails', '2.13.1' - user3277633

1 Answers

0
votes

Silly Me. In the tutorial there are two files that I did not look carefully at. One is static_pages_spec.rb under spec/requests and another is simply spec_helper.rb under spec. I messed up the two files and put the opposite things in one another.

I found my mistake after realizing " why do I need to require spec_helper.rb when I'm already in spec_helper.rb"