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 Write Our First Tests

Asa Smith
Asa Smith
10,009 Points

Syntax errors when running rspec tests?

rspec failure messages:

 1) Creating todo lists redirects to the todo list index page on success
     Failure/Error: visit "/todo_lists"
     SyntaxError:
       /home/asa/treehouse/projects/odot/app/models/todo_list.rb:3: syntax error, unexpected {, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
        validates :title. length:{minimum: 3}
                                  ^
     # ./app/controllers/todo_lists_controller.rb:7:in `index'
     # ./spec/features/todo_lists/create_spec.rb:5:in `block (2 levels) in <top (required)>'

  2) Creating todo lists displays an error when the todo list has no title
     Failure/Error: expect(TodoList.count).to eq(0)
     SyntaxError:
       /home/asa/treehouse/projects/odot/app/models/todo_list.rb:3: syntax error, unexpected {, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
        validates :title. length:{minimum: 3}
                                  ^
     # ./spec/features/todo_lists/create_spec.rb:17:in `block (2 levels) in <top (required)>'

  3) Creating todo lists displays an error when the todo list has a title less than 3 characters
     Failure/Error: expect(TodoList.count).to eq(0)
     SyntaxError:
       /home/asa/treehouse/projects/odot/app/models/todo_list.rb:3: syntax error, unexpected {, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
        validates :title. length:{minimum: 3}
                                  ^
     # ./spec/features/todo_lists/create_spec.rb:34:in `block (2 levels) in <top (required)>'
Asa Smith
Asa Smith
10,009 Points
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")

        fill_in "Title", with: "My todo list"
        fill_in "Description", with: "This is what I'm doing today." 
        click_button "Create Todo list"

        expect(page).to have_content("My todo list")
    end

    it "displays an error when the todo list has no title" do
        expect(TodoList.count).to eq(0) 

        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("")

        fill_in "Title", with: "My todo list"
        fill_in "Description", with: "This is what I'm doing today." 
        click_button "Create Todo list"

        expect(page).to have_content("error")
        expect(TodoList.count).to eq(0) 

        visit "/todo_lists"
        expect(page).to_not have_content("This is what I'm doing today.")
    end
    it "displays an error when the todo list has a title less than 3 characters" do
        expect(TodoList.count).to eq(0) 

        visit "/todo_lists"
        click_link "New Todo list"
        expect(page).to have_content("")

        fill_in "Title", with: "Hi"
        fill_in "Description", with: "This is what I'm doing today." 
        click_button "Create Todo list"

        expect(page).to have_content("error")
        expect(TodoList.count).to eq(0) 

        visit "/todo_lists"
        expect(page).to_not have_content("This is what I'm doing today.")
    end     


end

4 Answers

Tim Knight
Tim Knight
28,888 Points

Asa,

It looks like you have a syntax error in your validation code in your todo_list.rb model.

See how it's complaining on:

validates :title. length:{minimum: 3}

There's a period after the title when it should be a comma. So just change that to:

validates :title, length:{minimum: 3}

And that should get you there.

Asa Smith
Asa Smith
10,009 Points

Ah geez. I figured it was something simple like that. Thanks for your help.

Asa Smith
Asa Smith
10,009 Points

Now I get this failure:

Failures:

  1) Creating todo lists displays an error when the todo list has no title
     Failure/Error: expect(page).to have_content("error")
       expected to find text "error" in "Todo list was successfully created. Title: My todo list Description: This is what I'm doing today. Edit | Back"
     # ./spec/features/todo_lists/create_spec.rb:27:in `block (2 levels) in <top (required)>'
Tim Knight
Tim Knight
28,888 Points

See your section titled:

it "displays an error when the todo list has no title" do

Notice how underneath that you have:

fill_in "Title", with: "My todo list"

So you're actually giving it a title. It's expecting an error but it's being created successfully. I'd change that to:

fill_in "Title", with: ""