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 Viewing Todo Items: Part 2

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

I am not able to test my programs and am getting a error

This is what is showing up

treehouse:~/projects/odot (master) $ bin/rspec --format=documentation spec/features/todo_items/index_spec.rb /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in load': /home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb:27: syntax error, unexpected tLABEL, expecting ')' (SyntaxError) todo_list.todo_items.create (content: "Milk") ^ /home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb:27: syntax error, unexpected ')', expecting keyword_end /home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb:28: syntax error, unexpected tLABEL, expecting ')' todo_list.todo_items.create (content: "Eggs") ^ /home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb:28: syntax error, unexpected ')', expecting keyword_end from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inblock in load_spec_files' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in each' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inload_spec_files' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in run' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:inrun' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'

JONATHAN PACHA
JONATHAN PACHA
12,039 Points
unnamed_file.rb
require 'spec_helper'

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

    before do
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do
            click_link "List Items"
        end
    end

    it "displays the title of the todo list" do
        within("h1") do
            expect(page).to have_content(todo_list.title)
        end
    end

    it "displays no items when a todo list is empty" do
        expect(page.all("ul.todo_items li").size).to eq(0)
    end
end
JONATHAN PACHA
JONATHAN PACHA
12,039 Points
unnamed_file.rb
require 'spec_helper'

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

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

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

    it "redirects to the todo list index page on success" do
        create_todo_list
        expect(page).to have_content("My todo list")
    end

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

        create_todo_list title: ""

        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 am doing today.")
    end

    it "displays an error when todo list has a title less than characters" do
        expect(TodoList.count).to eq(0)

        create_todo_list title: "Hi"

        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 am doing today.")
    end

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

        create_todo_list title: "Grocery list", description: ""

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

        visit "/todo_lists"
        expect(page).to_not have_content("Grocery list")
    end

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

        create_todo_list title: "Grocery list", description: "Food"


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

        visit "/todo_lists"
        expect(page).to_not have_content("Grocery list")
    end
end

6 Answers

Hi Jonathan,

This has confused me a little. Your first code snippet is the one that's failing, I think. (Is that features/todo_items/index.spec?).

The code is failing at around line 27 with a syntax error near the code todo_list.todo_items.create (content: "Milk"). I can't see that code in your snippet. The test "displays item content when a todo list has items" should contain this. The same error but for "Eggs" is occurring at line 28.

Is this all your code and is the right file?

Steve.

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

It is the same file and there is no line 27. Can I go back and de-commit previous lessons and start again?

require 'spec_helper'

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

    before do
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id}" do
            click_link "List Items"
        end
    end

    it "displays the title of the todo list" do
        within("h1") do
            expect(page).to have_content(todo_list.title)
        end
    end

    it "displays no items when a todo list is empty" do
        expect(page.all("ul.todo_items li").size).to eq(0)
    end
end

Hi Jonathan,

I'm really sorry but I have no better suggestion than to roll that back and try again. The line /home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb:27: says that line 27 of your index_spec.rb file is causing a problem. I have no idea how that could not reflect your code accurately.

Very odd indeed!!

Roll it back and let's go from there - keep me involved, I'm intruiged as to how that can happen.

Thanks,

Steve.

Asa Smith
Asa Smith
10,009 Points

I'm having the same problem but with a different syntax error

.rb:39: syntax error, unexpected keyword_end, expecting tSTRING_DEND

Hi Asa,

Can you post your code, please - I'll see if I can figure out what's wrong with it!

Cheers,

Steve.

Asa Smith
Asa Smith
10,009 Points

Thanks Steve

require 'spec_helper'

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

    def visit_todo_list(list)
        visit "/todo_lists"
        within "#todo_list_#{todo_list.id"}" do 
            click_link "List Items"     
    end
end

it "displays the title of the todo list" do
    visit_todo_list(todo_list)
    within("h1") do
        expect(page).to have_content(todo_list.title)
    end
end


it "displays no items when a todo list is empty" do
    visit_todo_list(todo_list)
    expect(page.all("ul.todo_items li").size).to eq (0)
end

it "displays item content when a todo list has items" do
    todo_list.todo_items.create(content:"Milk")
    todo_list.todo_items.create(content:"Eggs")

    visit_todo_list(todo_list)

    expect(page.all("ul.todo_items li").size).to eq (2)

    within "ul.todo_list" do 
        expect(page).to have_content("Milk")
        expect(page).to have_content("Eggs")
        end
    end
end

That's an interesting one!

Your problem is here, on line 8:

within "#todo_list_#{todo_list.id"}" do 

You've left a string open which is affecting the rest of the file. It should read like:

within("#todo_item_#{todo_item.id}") do

So you need to delete the double-quote before the last curly brace. That then opens up the rest of the ruby code to be parsed as code rather than a string. Your error found the end keyword but expected a string terminator.

I think that should sort it for you. Let me know if not!

Steve.

I had an issue with emails not firing for this post to notify of new additions, so I thought it best to tag Asa Smith to ensure you were notified!

Donald Gray II
Donald Gray II
5,341 Points

So that we can help you, please post the contents of the file located here:

/home/treehouse/projects/odot/spec/features/todo_items/index_spec.rb

If you post that exact file, we should be able to assist you. In the unnamed_file.rb that you posted, you haven't included the tests that check to see if the todo items added actually appear on the page.

The error appears in this block:

it "displays item content when a todo list has items" do
        todo_list.todo_items.create(content: "Milk")
        todo_list.todo_items.create(content: "Eggs")

        visit_todo_list(todo_list)

        expect(page.all("ul.todo_items li").size).to eq(2)

        within "ul.todo_items" do           
            expect(page).to have_content("Milk")
            expect(page).to have_content("Eggs")
        end
    end
end

None of the code that you have posted thus far includes the lines that the error is referencing.