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

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

I'm always getting two errors when ever I run my test.

Hi, I'm always getting two errors when ever I run my test.

Here's my code below in create_rspec.rb, and then what the terminal returns:

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
alborzs-mbp:odot alborz$ 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: click_link "New Todo List"
     Capybara::ElementNotFound:
       Unable to find link "New Todo List"
     # ./spec/features/todo_lists/create_spec.rb:6:in `block (2 levels) in <top (required)>'

  2) Creating todo lists displays an error when the todo list has no title
     Failure/Error: click_link "New Todo List"
     Capybara::ElementNotFound:
       Unable to find link "New Todo List"
     # ./spec/features/todo_lists/create_spec.rb:20: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 /Users/alborz/.rvm/gems/ruby-2.1.1/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 /Users/alborz/.rvm/gems/ruby-2.1.1/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.04601 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 21337

alborzs-mbp:odot alborz$ clear

alborzs-mbp:odot alborz$ 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: click_link "New Todo List"
     Capybara::ElementNotFound:
       Unable to find link "New Todo List"
     # ./spec/features/todo_lists/create_spec.rb:6:in `block (2 levels) in <top (required)>'

  2) Creating todo lists displays an error when the todo list has no title
     Failure/Error: click_link "New Todo List"
     Capybara::ElementNotFound:
       Unable to find link "New Todo List"
     # ./spec/features/todo_lists/create_spec.rb:20: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 /Users/alborz/.rvm/gems/ruby-2.1.1/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 /Users/alborz/.rvm/gems/ruby-2.1.1/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.04826 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 58097

The strange thing is that when I still go ahead and test the functionality by clicking "Create Todo list", I am able to successfully see the error messages written to the page.

Thanks!

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

My bet is that your page says "New Todo list" and your test says click_link "New Todo List". Just make the capitalization identical in both.