1

I am trying to follow TDD on Rails Tutorial which is available online here

While testing first app, I got an error.

My spec.rb code is this:

require 'spec_helper'

describe "Static pages" do
  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      page.should have_content('Sample App')
    end
  end
end

After running testing I got this error:

Failure/Error: visit '/static_pages/home'
 NoMethodError:
   undefined method `visit' for #    <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa833e5c># ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

I will really appreciate your help.

2
  • Does this help: stackoverflow.com/questions/8862967/… Commented Mar 8, 2012 at 11:42
  • What is the file's path and name? Is it spec/requests/static_pages_spec.rb like in the tutorial? Rspec is quite "magical" about its available and included test helpers and methods based on the name of the file, I have found. Commented Mar 8, 2012 at 11:43

2 Answers 2

3

The visit method is not part of RSpec - it's provided by capybara. Just add this to your Gemfile:

gem 'capybara'
Sign up to request clarification or add additional context in comments.

6 Comments

I already have capybara installed but I get the same error? I see capybara 1.1.2 installed in my gemfile list and also "gem list" command results. Do you have any idea?
@scaryguy Just a shot in the dark - try include Capybara::DSL in your spec_helper.rb or directly in your spec.
@Thilo I resolved the issue yesterday, thanks anyway :) At the moment, I'm busy with pulling my hair working on nokogiri...
@scaryguy how did you resolve this issue? Im curious as i have the same issue. I tried including Capybara::DSL in spec_helper.rb but it warns me not to include capybara in a global space... ?
I'm sorry @sambehera I really don't remember, it's been a while since I worked on that project.
|
0

Try add:

require 'rails_helper'
require 'spec_helper'

to your spec.rb and:

require 'capybara'

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

to spec_helper.rb

and gem 'capybara', '2.2.0' to gemfile

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.