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

Todd MacIntyre
Todd MacIntyre
12,248 Points

E.xtra failure + depreciation warnings

I need some help. I've spent way too many hours trying to resolve this, but alas I'm just not sure I can solve it on my own as a newbie. Please find below my code followed by the console output after running my rspec test.

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") # Change to "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") # Change to "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

Failures

$ bin/rspec spec/features/todo_lists/create_spec.rb 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(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:21: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 C:/Ruby22-x64/lib/ruby/gems/2.2.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 C:/Ruby22-x64/lib/ruby/gems/2.2.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.26 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 13588

6 Answers

Hi Todd,

You're test is slightly incorrect.

Change what it expects to see from "New todo_list" to "New Todo List". Your test is looking for something, incorrectly, different to what your view is showing.

Let me know how you get on; I can be more specific.

Steve.

I added two comments in your code. Let me know if you're OK with that.

Steve.

Todd MacIntyre
Todd MacIntyre
12,248 Points

Thanks for your quick response, Steve. However, I made those two changes but am still receiving the same errors and depreciations. Also, I am confused because at 06:39 in the video, it clearly shows the instructor using "New todo_list" including the underscore. Any other tips?

First, let's ignore the deprecation warnings; we can deal with those separately.

Next, it is impossible to receive the same test fails if you changed what I suggested. We may have created new errors, though! Paste your fail messages in here and we can go from there. This is good - this is progress.

And, yes, there are stacks of posts on this issue having been following the video. And you'll come across more discrepancies too; again, this is good - it makes you dig into your project and get to know it.

Keep reading your error messages and understanding what they are saying. Translate that into your code and plug away at fixing stuff. It'll really help. But make sure you set a Git commit before you start playing! Lol.

Todd MacIntyre
Todd MacIntyre
12,248 Points

Thanks Steve for your willingness to help. This is the new error message:

$ bin/rspec spec/features/todo_lists/create_spec.rb
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(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:21:in `block (2 levels) in <top (required)>'

2 deprecation warnings total

Finished in 0.29 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 31524

essentially the same thing, but with the change being reflected in the console output slightly.

Hi Todd,

Steve suggested that you change your test to check for "New Todo List", each word capitalized. You have in your test "New Todo list".

So there is still a mismatch between what your test is expecting to find and the actual content on your page.

This part of the error message shows the mismatch:

...expected to find text "New Todo list" in "New Todo List Title Description Back"...

The first set of quotes is what your test expected to find and the 2nd set of quotes shows the actual text content that the view is producing. If it can't find an exact match somewhere in the content then you will get this type of error message.

The solution is to either change what is in the view to match the test or change the test to match what's in the view.

Todd MacIntyre
Todd MacIntyre
12,248 Points

One more thought. I have found that I am unable to destroy previously created todo lists. It appears a log of them is kept in the /log/development.log file, but the destroy method elsewhere in the code must not be working correctly to remove these. Could this have something to do with the rspec console errors I am receiving?

Hi Todd,

I think the Rspec errors you are receiving are not related to the inability to call the destroy method from your todo_list_controller.rb file. The errors are caused by your test text not matching your view text, as Jason further described above.

Your controller file should have the destroy method defined in it and that should contain @todo_list.destroy and then a redirect to your index page. Post your controller code, and we can have a look at it to see what might be wrong.

As for the deprecations, they say to add this code to your spec_helper.rb file. That should suppress the warnings. But they are just that, warnings, and can be safely overlooked for our purposes. Code:

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

Give that a try and let me know how you get on - I hope you got your tests fixed too. Apologies for not replying to the thread last night; it was time for sleep!

Steve.

Todd MacIntyre
Todd MacIntyre
12,248 Points

No apologies needed, I appreciate your help! I'll look into this and let you know soon.

:+1:

Hi Todd,

I was having the same errors and found a solution (that at least works for me) I am building my project locally and NOT through the VM

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: "Listing Todo Lists"
        fill_in "Description", with: "This is what I'm doing today."
        click_button "Create Todo list"


        expect(page).to have_content("Listing Todo Lists")
    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