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

can't solve failures...

I wrote on a terminal, "bin/rspec spec/features/todo_lists/create_spec.rb" and run. I did the same way as the video, but couldn't solve failures :(

My code is

<create_spec.rb>

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 "Tiile", 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(TodoLists.count).to eq(0)

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

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

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

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

<todo_lisit.rb>
class TodoList < ActiveRecord::Base
    validates :title, presence: true
end

and terminal said

2 deprecation warnings total

Finished in 0.40317 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:16 # Creating todo lists displays an error when the 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

Randomized with seed 44208

Is there anyone who can help me? Thanks!

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This error does not say much. We don't know which expectation fails exactly. You have to copy the whole errors and paste here, this will guide us to the proper line, what was expected and what the test got instead. But for now, this is wrong:

fill_in "Tiile", with: ""

Change it to Title, maybe it will help. if not, paste the whole errors.

Thank you for your advice :) I fixed that typo, but it still appeared the error message. This is the whole errors;

treehouse:~/projects/odot (master *) $ bin/rspec spec/features/todo_lists/create_spec.rb [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. FF

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 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(TodoLists.count).to eq(0) NameError: uninitialized constant TodoLists # ./spec/features/todo_lists/create_spec.rb:17:in `block (2 levels) in <top (required)>'

Deprecation Warnings:


RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:

  • rspec-core's DSL methods (it, before, after, let, subject, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts.
  • The current example is now exposed via RSpec.current_example, which is accessible from any context.
  • If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:

    RSpec.configure do |c| c.expose_current_running_example_as :example end

(Called from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')


RSpec::Core::ExampleGroup#example is deprecated and will be removed in RSpec 3. There are a few options for what you can use instead:

  • rspec-core's DSL methods (it, before, after, let, subject, etc) now yield the example as a block argument, and that is the recommended way to access the current example from those contexts.
  • The current example is now exposed via RSpec.current_example, which is accessible from any context.
  • If you can't update the code at this call site (e.g. because it is in an extension gem), you can use this snippet to continue making this method available in RSpec 2.99 and RSpec 3:

    RSpec.configure do |c| c.expose_current_running_example_as :example end

(Called from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>')

If you need more of the backtrace for any of these deprecations to identify where to make the necessary changes, you can configure config.raise_errors_for_deprecations!, and it will turn the deprecation warnings into errors, giving you the full backtrace.

2 deprecation warnings total

Finished in 0.47441 seconds 2 examples, 2 failures

Failed examples:

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

Randomized with seed 14366

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, so these are your two errors:

1) This: expected to find text "New Todo_list" in "New todo_list Title Description Back" tells you that you have a capital letter in expectation and a lowercase letter in the actual code. Change your spec line 7 to this:

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

2) This: expect(TodoLists.count).to eq(0) NameError: uninitialized constant TodoLists tells you that you used plural form when referring to the model. You should use this in line 17:

expect(TodoList.count).to eq(0)

thank you!! I'll try :)