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.

Thilo
  • 17,565
  • 5
  • 68
  • 84
chhantyal
  • 11,874
  • 7
  • 51
  • 77
  • Does this help: http://stackoverflow.com/questions/8862967/visit-method-not-found-in-my-rspec – wintersolutions Mar 08 '12 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. – berkes Mar 08 '12 at 11:43

2 Answers2

3

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

gem 'capybara'
Thilo
  • 17,565
  • 5
  • 68
  • 84
  • 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 Aug 29 '12 at 13:24
  • @scaryguy Just a shot in the dark - try `include Capybara::DSL` in your `spec_helper.rb` or directly in your spec. – Thilo Aug 30 '12 at 02:19
  • @Thilo I resolved the issue yesterday, thanks anyway :) At the moment, I'm busy with pulling my hair working on nokogiri... – scaryguy Aug 31 '12 at 01:31
  • @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... ? – sambehera Jan 12 '13 at 04:17
  • I'm sorry @sambehera I really don't remember, it's been a while since I worked on that project. – scaryguy Jan 12 '13 at 12:53
  • thanks for feedback.. i figured out how to bypass the Capybara::DSL part by reading the capybara github readme. TY. – sambehera Jan 13 '13 at 02:36
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

Victor
  • 897
  • 8
  • 4