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 Todo Items

gerald blady
gerald blady
9,052 Points

Ruby - Adding Todo Items message unable to find save button

here is the error message:

Failures:

1) Adding todo items is successful with valid content Failure/Error: click_button "Save" Capybara::ElementNotFound: Unable to find button "Save" # ./spec/features/todo_items/create_spec.rb:17:in `block (2 levels) in <top (required)>'

It's directing me to rb:17 which is the << click_button "Save" >> not sure what is wrong here?

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.")
    within("ul.todo_items") do
        expect(page).to have_content("Milk")
    end
end

end

then in the new.html.erb i have this

<%= form_for [@todo_list, @todo_item] do |form| %> <%= form.label :content %> <%= form.text_field :content %>

<% form.submit "Save" %>

<% end %>

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This:

<% form.submit "Save" %>

Notice that it does not have the = symbol after the <%. This means it is not displayed on the page. Once you add this, the test should work.

gerald blady
gerald blady
9,052 Points

A simple '=' sign. bah! New set of eyes helps! Thank you much

But of course... New error..

Failures:

1) Adding todo items is successful with valid content Failure/Error: expect(page).to have_content("Added todo list item.") expected to find text "Added todo list item." in "Grocery list Milk New Todo Item" # ./spec/features/todo_items/create_spec.rb:18:in `block (2 levels) in <top (required)>'

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Looks like you are not displaying the notice. The only content on your page at this point is "Grocery list Milk New Todo Item". This means that either you didn't specify markup for notices/alerts in your layout or in your controller action there is no notice/alert after the redirect.