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

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

rspec test Failure!

I have gone back and redone completely this app build and have twice now received the same message when running the bin/rspec spec/features/todo_lists/create_spec.rb the message being failed examples: bin/rspec spec/features/todo_list/creat_spec.rb:4 #Creating todo lists redirects to todo list index page on success.

here is my code: require 'spec_helper'

describe "Creating todo lists" do it "redirects to todo list index page on success" do visit "/todo_lists" click_link "New Todo list" expect(page).to have_content("New Todo list")

  end

end

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

im getting the same error when i attempt to apply an error message to the page with: it "displays an error when todo list has no title" do

PLEASE HELP! I have now gone back and reinstalled ruby and a new VM and have redone all of the builds to the current video. I have checked and rechecked all of my syntax and its not working. Thank You.

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

I'm having issues with line 4 and 16 coming up failures. Nothing to do with the New List.

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:16 # Creating todo lists displays an error when todo list has no title rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo list index page on success

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

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

    fill_in "Title", with: ""
    fill_in "Description", with: "This is what I am 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 am doing today.")
end

I would suggested taking a look at the project files and comparing what you have to see if something is miss typed.

Mark Stansbury mentioned each version of rails generating different text, but in my case it generated the same thing in the videos and I am using the newest version of rails.

again in the test

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("New todo_list")

    fill_in "Title", with: ""
    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

the expect(page).to have_content("New todo_list") depends on the content in your html.erb file that corresponds.

So if the page has New todo_list and the test expects New Todo List the strings would not be similar and this would cause the test to fail.

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

Andrew, its fixed. Thank you very much. I matched the New todo_list with my html.erb file. I am still perplexed as to why the failures were shown on a different line though; 4 and 16 rather than 7 and 21.

That is great! Glad you figured it out :)

I had quite a lot of trouble with this course myself (tiny little things here and there.... then it kind of gets a bit harder at the end due to lack of compatibility and explanation) , but if you have any more questions make a forum post and I will try and help!

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

Andrew, it is fixed. Thank you very much for your patience. I went in and matched the New todo_list with the html.erb file and its copacetic. I am still rather perplexed as to why the failures were showing up on lines 4 and 16 rather than 7 and 21.

4 Answers

JONATHAN PACHA
JONATHAN PACHA
12,039 Points

I tried that Andrew. But I am still having rspec errors. I am still unclear as to whats going on.

Mark Stansbury
Mark Stansbury
2,603 Points

Jon,

Try adjusting your capitalization as follows:

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

Note that the link title is "New Todo list" while the displayed content is "New Todo List". I don't know why "List" is capitalized in one instance and not in the other, but that catch fixed the problem for me. And from what I can tell, if you've been following along, you will not have the title "New todo_list".

Send us over some of the code so we can see if there are any other errors.

Sorry, it seems I might have changed a few lines of code in my project that might differ from the course; but from re watching the video he has written the test to visit the todo_lists site, click 'New Todo list' link, expect 'New todo_list' then fill out the information needed, click the 'Create Todo list' button then expect the page to have content 'My todo list'

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")

If you could send us your ./app/views/todo_lists/ folder (Specifically new.html.erb and index.html.erb should be enough) and the spec then we could see whats going on

  it "redirects to todo list index page on success" do 
    visit "/todo_lists" 
    click_link "New Todo list" 
    expect(page).to have_content("New todo_list")
  end

It must be

expect(page).to have_content("New todo_list")

Not

expect(page).to have_content("New Todo list")

Basically we are testing for the text "New todo_list" on the index page for todo_lists which is store in app/views/todo_lists/index.html.erb

If you check out that file you will see that "New Todo list" cannot be found, only "New todo_list" (Assuming you have been following along)

I do apologize if I write down the wrong paths, I have this project on another computer so I will checkout the files tomorrow morning and update you some more on what is happening!

Mark Stansbury
Mark Stansbury
2,603 Points

The title probably generates differently depending on what version of Rails the user has installed. At least for me, using Rails 4.2 and Ruby 2.1, it generated as "New Todo List" with no underscore and all three words capitalized. The link, on the other hand, generated as "New Todo list" with the last word in lower case.