Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Adam Short
Adam Short
11,153 Points

Undefined methods for rspec

My code 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

it looks identical to the teacher's, with the exception of "New Todo List" instead of "New Todo_List" (oddly, the _ isn't showing up for me).

the problem is, I keep getting errors that look like this:

Failure/Error: click_link "New Todo list"

 NoMethodError:
   undefined method `click_link' for #<RSpec::ExampleGroups::CreatingTodoLists:0x007f9149426cb0>
 # ./spec/features/todo_lists/create_spec.rb:5:in `block (2 levels) in <top (required)>'

I'm not sure what is going on here? Could someone please point out my error?

Thank you!

3 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Adam,

Did you get this fixed? That looks like a strange error.

Steve.

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Adam,

This almost looks as though your app doesn't understand what Capybara is doing. In spec_helper.rb, do you have:

require 'capybara/rails'
require 'capybara/rspec'

Steve.

Sean Leber-Fennessy
Sean Leber-Fennessy
Front End Web Development Techdegree Student 6,502 Points

I have the same error, here are my errors:

Failed examples:

rspec ./spec/controllers/todo_lists_controller_spec.rb:135 # TodoListsController PUT update with invalid params re-renders the 'edit' template
rspec ./spec/controllers/todo_lists_controller_spec.rb:127 # TodoListsController PUT update with invalid params assigns the todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:113 # TodoListsController PUT update with valid params assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:103 # TodoListsController PUT update with valid params updates the requested todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:57 # TodoListsController GET edit assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:92 # TodoListsController POST create with invalid params re-renders the 'new' template
rspec ./spec/controllers/todo_lists_controller_spec.rb:85 # TodoListsController POST create with invalid params assigns a newly created but unsaved todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:72 # TodoListsController POST create with valid params assigns a newly created todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:42 # TodoListsController GET show assigns the requested todo_list as @todo_list
rspec ./spec/controllers/todo_lists_controller_spec.rb:153 # TodoListsController DELETE destroy redirects to the todo_lists list
rspec ./spec/controllers/todo_lists_controller_spec.rb:34 # TodoListsController GET index assigns all todo_lists as @todo_lists
rspec ./spec/controllers/todo_lists_controller_spec.rb:50 # TodoListsController GET new assigns a new todo_list as @todo_list

I'm not sure if some of these problems are coming from different gem versions. I started the project using rails 5, with the same version of the gems listed in the project. I tried using newer gems and ran into similar errors, which is why I restarted the project and used the older gem versions hoping that would clear things up, but it's still happening.

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Hi Sean,

I'm out at the moment but will look in more detail when I get home.

Can you post your test code, please?

Thanks,

Steve.

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Maybe also run your test suite using rspec --format documentation as this might give you a little more detail as to why the tests aren't passing. The issue is in your app, not the tests (unless the tests are asserting nonsense!).

Essentially, your test code syntax is fine; but your application's code isn't passing the tests. This may well be because you're using Rails 5 - these courses are in Rails 4. I've not used 5 yet so there may be differences.

Have you been uploading your code to a remote git repository using Github or Bitbucket? I can pull your code down, or just view it, if you have.

Steve.