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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Rspec test failed for creating todo list

I get the following output when running rspec

Failures:

1) Creating todo lists redirects to the todo list index page on success Failure/Error: visit "/todo_lists" NoMethodError: undefined method visit' for #<RSpec::ExampleGroups::CreatingTodoLists:0x000000022e4620> # ./spec/features/todo_lists/create_spec.rb:7:inblock (2 levels) in <top (required)>'

Finished in 0.0007 seconds (files took 0.49916 seconds to load) 1 example, 1 failure

Failed examples:

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

my create_spec.rb is as follows

require 'spec_helper'


describe "Creating todo lists" do

    it "redirects to the todo list index page on success" do
        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("New Todo List")

    end


end

I thought it might be a typo on the new.html.erb page, but I can't see it. Below is a copy of the code for that page.

<h1>New Todo List</h1>

<%= render 'form' %>

<%= link_to 'Back', todo_lists_path %>

Help!!

1 Answer

Found the problem. I don't know why but using require "rails_helper" instead of "spec_helper" fixed the issue.

The following link explains why require "rails_helper" works and "spec_helper" doesn't. It depends on you version of rspec. Below i sthe link to the article.

https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files