Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Editing Todo Lists

Frank de Wolf
Frank de Wolf
5,413 Points

I get 5 failures, all the same: undefined method 'update_todo_list' for #<RSpec::...EditingTodoLists:...>

Unfortunately I can't find the solution, any help will be more than welcome!

Failures:

1) Editing todo lists displays an error with too short a title Failure/Error: update_todo_list todo: todo_list, title: "Hi"

 NoMethodError:
   undefined method `update_todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fcdec55cfc8>
 # ./spec/features/todo_lists/edit_spec.rb:43:in `block (2 levels) in <top (required)>'

2) Editing todo lists displays an error with too short a description Failure/Error: update_todo_list todo: todo_list, description: "hi"

 NoMethodError:
   undefined method `update_todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fcdec6e2028>
 # ./spec/features/todo_lists/edit_spec.rb:53:in `block (2 levels) in <top (required)>'

3) Editing todo lists displays an error with no description Failure/Error: update_todo_list todo: todo_list, description: ""

 NoMethodError:
   undefined method `update_todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fcdeb71df48>
 # ./spec/features/todo_lists/edit_spec.rb:48:in `block (2 levels) in <top (required)>'

4) Editing todo lists displays an error with no title Failure/Error: update_todo_list todo: todo_list, title: ""

 NoMethodError:
   undefined method `update_todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fcdeb75fda8>
 # ./spec/features/todo_lists/edit_spec.rb:35:in `block (2 levels) in <top (required)>'

5) Editing todo lists updates a todo list successfully with correct information Failure/Error: update_todo_list todo_list: todo_list, title: "New title", description: "New description"

 NoMethodError:
   undefined method `update_todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fcdeb79f318>
 # ./spec/features/todo_lists/edit_spec.rb:23:in `block (2 levels) in <top (required)>'

Finished in 0.04468 seconds (files took 2.17 seconds to load) 5 examples, 5 failures

3 Answers

Frank de Wolf
Frank de Wolf
5,413 Points

Sorry...

require 'spec_helper'

describe "Editing todo lists" do let!(:todo_list) {TodoList.create(title: "Groceries", description: "Grocery list")}

def create_todo_list(options={}) options[:title] ||= "My todo list" options[:description] ||= "This is my todo list"

todo_list = options[:todo_list]

within "#todo_list_#{todo_list.id}" do
  click_link "Edit"
end

fill_in "Title", with: options[:title]
fill_in "Description", with: options[:description]
click_button "Update Todo list"

end

it "updates a todo list successfully with correct information" do todo_list = TodoList.create(title: "Groceries", description: "Grocery list") update_todo_list todo_list: todo_list, title: "New title", description: "New description"

todo_list.reload

expect(page).to have_content("Todo list was successfully updated")
expect(todo_list.title).to eq("New title")
expect(todo_list.description).to eq("New description")

end

it "displays an error with no title" do update_todo_list todo: todo_list, title: "" title = todo_list.title todo_list.reload expect(todo_list.title).to eq(title) expect(page).to have_content("error") end

it "displays an error with too short a title" do update_todo_list todo: todo_list, title: "Hi" expect(page).to have_content("error") end

it "displays an error with no description" do update_todo_list todo: todo_list, description: "" expect(page).to have_content("error") end

it "displays an error with too short a description" do update_todo_list todo: todo_list, description: "hi" expect(page).to have_content("error") end end

Frank de Wolf
Frank de Wolf
5,413 Points

Found some errors in the code myself and changed this, unfortunately now I get these failures:

  1) Editing todo lists displays an error with too short a description
     Failure/Error: update_todo_list todo_list: todo_list, description: "hi"

     NameError:
       undefined local variable or method `todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fbb54baaad8>
       Did you mean?  todo_list_url
     # ./spec/features/todo_lists/edit_spec.rb:52:in `block (2 levels) in <top (required)>'

  2) Editing todo lists displays an error with too short a title
     Failure/Error: update_todo_list todo_list: todo_list, title: "Hi"

     NameError:
       undefined local variable or method `todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fbb54ba2e00>
       Did you mean?  todo_list_url
     # ./spec/features/todo_lists/edit_spec.rb:42:in `block (2 levels) in <top (required)>'

  3) Editing todo lists displays an error with no title
     Failure/Error: update_todo_list todo_list: todo_list, title: ""

     NameError:
       undefined local variable or method `todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fbb54b9a868>
       Did you mean?  todo_list_url
     # ./spec/features/todo_lists/edit_spec.rb:34:in `block (2 levels) in <top (required)>'

  4) Editing todo lists updates a todo list successfully with correct information
     Failure/Error:
         within "#todo_list_#{todo_list.id}" do
           click_link "Edit"
       end

     Capybara::ElementNotFound:
       Unable to find css "#todo_list_109"
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/node/finders.rb:41:in `block in find'
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/node/base.rb:84:in `synchronize'
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/node/finders.rb:30:in `find'
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/session.rb:585:in `block (2 levels) in <class:Session>'
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/session.rb:278:in `within'
     # /Users/Frank/.rvm/gems/ruby-2.3.0/gems/capybara-2.3.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./spec/features/todo_lists/edit_spec.rb:11:in `update_todo_list'
     # ./spec/features/todo_lists/edit_spec.rb:22:in `block (2 levels) in <top (required)>'

  5) Editing todo lists displays an error with no description
     Failure/Error: update_todo_list todo_list: todo_list, description: ""

     NameError:
       undefined local variable or method `todo_list' for #<RSpec::ExampleGroups::EditingTodoLists:0x007fbb54a52cf8>
       Did you mean?  todo_list_url
     # ./spec/features/todo_lists/edit_spec.rb:47:in `block (2 levels) in <top (required)>'

CODE:
require 'spec_helper'

describe "Editing todo lists" do

  def update_todo_list(options={})
    options[:title] ||= "My todo list"
    options[:description] ||= "This is my todo list"

    todo_list = options[:todo_list]

    within "#todo_list_#{todo_list.id}" do
      click_link "Edit"
  end

    fill_in "Title", with: options[:title]
    fill_in "Description", with: options[:description]
    click_button "Update Todo list"
  end

  it "updates a todo list successfully with correct information" do
    todo_list = TodoList.create(title: "Groceries", description: "Grocery list")
    update_todo_list todo_list: todo_list,
                     title: "New title",
                     description: "New description"

    todo_list.reload

    expect(page).to have_content("Todo list was successfully updated")
    expect(todo_list.title).to eq("New title")
    expect(todo_list.description).to eq("New description")
  end

  it "displays an error with no title" do
    update_todo_list todo_list: todo_list, title: ""
    title = todo_list.title
    todo_list.reload
    expect(todo_list.title).to eq(title)
    expect(page).to have_content("error")
  end

  it "displays an error with too short a title" do
    update_todo_list todo_list: todo_list, title: "Hi"
    expect(page).to have_content("error")
  end

  it "displays an error with no description" do
    update_todo_list todo_list: todo_list, description: ""
    expect(page).to have_content("error")
  end

  it "displays an error with too short a description" do
    update_todo_list todo_list: todo_list, description: "hi"
    expect(page).to have_content("error")
  end
end