Question

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.

Was it helpful?

Solution

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

gem 'capybara'

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top