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

getting failure when adding todo items

I have seen this error posted and corrected but still cannot solve my issue. Here is the error.

Adding todo items
  is successful with valid content
  displays an error with no content (FAILED - 1)

Failures:

  1) Adding todo items displays an error with no content
     Failure/Error: expect(page).to have_content("There was a problem adding that todo list item")
       expected to find text "There was a problem adding that todo list item" in "There was an error adding that todo list item"
     # ./spec/features/todo_items/create_spec.rb:28:in `block (3 levels) in <top (required)>'
     # ./spec/features/todo_items/create_spec.rb:27:in `block (2 levels) in <top (required)>'

Finished in 0.27938 seconds
2 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_items/create_spec.rb:22 # Adding todo items displays an error with no content

Randomized with seed 27454

And here is my create spec

require 'spec_helper'

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

  def visit_todo_list(list)
    visit "/todo_lists"
    within "#todo_list_#{list.id}" do
      click_link "List Items"
    end
  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")    
    expect(page).to have_content("Milk")
  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

end

Solved it. I had the wrong message in my todo_items_controller.rb. Duh