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

Julius Michael
Julius Michael
8,967 Points

2 failures when trying to excute code on ruby on rails

Hi This is my code:

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

end

When I run, it failed twice.

Failures:

1) Creating todo lists redirects to the todo list index page on success Failure/Error: expect(page).to have_content("New todo_list") expected to find text "New todo_list" in "New Todo List Title Description Text Back" # ./spec/features/todo_lists/create_spec.rb:7: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) TypeError: Cannot visit ThreadSafe::Array # ./spec/features/todo_lists/create_spec.rb:18:in `block (2 levels) in <top (required)>'

I'm very new to ruby on rails. Can someone help me out please?

1 Answer

Thomas Tilton-Heylin
Thomas Tilton-Heylin
12,098 Points

So I also had these same problems as what many of you are having the steps that I took are the following:

Step 1,

Log into Terminal Navigate to ./treehouse/projects

cd treehouse/projects 

then run

vagrant ssh

you are now logged into the VM

Step 2,

While in the VM, treehouse:~/projects/odot (master) $`

run bundle

make a git commit

Step 3,

Run bin/rails generate rspec:install

hit "Y" to force

git commit

Step 4,

Run bundle binstubs rspec-core --force

git commit

Step 5,

Run bin/rake db:migrate Run bin/rake db:migrate RAILS_ENV=test

git commit

Step 6,

Rewrite "create_spec.rb" using the video "Write out our first tests" and go from there.

This acts as a factory reset for the gems and whatnot you install in the other lessons that people like myself may have messed up. I had the same error messages as well.

This method worked for me and I was able to run the test with/without the proper failures that are shown in the video.

On a side note I went through the steps that terminal told me to use for solving this problem and it was a farce.

Spell check your "create_spec.rb" and make sure everything matches up in the video.