Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Tatiana Perry
Tatiana Perry
17,156 Points

I am getting a No Method Error for 'Writing our First tests"

require 'spec_helper'

describe "Creating do to lists" do
    it "redirects to the to do list index page on success" do 
        visit "/todo_lists"
        click_link "New Todo lists"
        expect(page).to have_content("New todo_lists")
    end
end

And the console:

Failures:

  1) Creating do to lists redirects to the to do list index page on success
     Failure/Error: visit "todo_lists"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000002bcd070>
     # ./spec/features/todo_lists/create_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00085 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating do to lists redirects to the to do list index page on success

2 Answers

David Gross
David Gross
19,443 Points

In the spec_helper.rb add

require 'capybara/rails'

if you are still having trouble under Rspec config add

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

Also make sure you have the capybara gem in your gemfile

Tatiana Perry
Tatiana Perry
17,156 Points

I had to add

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

Thanks