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 Adding Validations to Todo Items

it "displays an error with no content" test fails.. click_button "Save" NoMethodError

Performing the second test in the create_spec.rb file "displays an error with no content.... I get an error at click_button "Save" NoMethodError. even though the save type of test was performed earlier successfully. I don't even remember creating a save button. guess I'm lost. Any suggestions on fixing the bug so I can continue? Seems it broke when i added the validation in the todo_item.rb model

class TodoItem < ActiveRecord::Base
  belongs_to :todo_list

  validates :content, presence: true
end
it "is successful with valid content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: "Milk"
    click_button "Save"
    expect(page).to have_content("Added todo list item.")
    within("ul.todo_items") do
      expect(page).to have_content("Milk")
    end
  end

  it "displays an error with no content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: ""
    click_button "Save"
    within("div.flash") do
      expect(page).to have_content("There was a problem adding that todo list item.")
    end
    expect(page).to have_content("Content can't be blank.")
  end

Right after test failure "expect(page).to have_content("There was a problem adding that todo list item.")

I've check 100 times and can't find any consistency .. especially whereas the previous test passes with similar requirements.

2 Answers

Hossam Khalifa
Hossam Khalifa
17,200 Points

Check your controller mostly the create method and the error should actually give you the filename and line number

Thanks, yeah it is always a typo.. Good call on the controller