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

First Tests already getting rspec error;

So, just starting this project and trying to test the create_spec.rb and this what it has inside..

require 'spec_helper'

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

I am requiring capybara/rspec in spec helper;

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'

So when running it as..

bin/rspec spec/features/todo_lists/create_spec.rb

It prints back;

F

Failures:

  1) Creating todo lists redirects to the todo list index page on success
     Failure/Error: clink_link "New Todo list"
     NoMethodError:
       undefined method `clink_link' for #<RSpec::Core::ExampleGroup::Nested_1:0xba5c460c>
     # ./spec/features/todo_lists/create_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.25049 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo list index page on success

Randomized with seed 26951

Any chance on what I'm doing wrong already?

gemfile:

source 'https://rubygems.org'

gem 'rails', '4.0.1'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :development, :test do
    gem 'rspec-rails', '~> 2.0'
end

group :test do
    gem 'capybara', '~> 2.1.0'
end

7 Answers

did you manage to solve this? i get the same error and havnt found a solution :(

Nick Fuller
Nick Fuller
9,027 Points

I'm assuming this is a feature spec right?

Try...

require 'spec_helper'

feature "Creating todo lists" do
    scenario "redirects to the todo list index page on success" do
        visit "/todo_lists"
        clink_link "New Todo list"
        expect(page).to have_content("New todo_list")
    end
end

Yes, pretty positive. I replaced your code with mine which the difference was scenario vs it and still came up with same error.

treehouse:~/projects/odot (master *) $ bin/rspec spec/features/todo_lists/create_spec.rb -f d

Creating todo lists
  redirects to the todo list index page on success (FAILED - 1)

Failures:

  1) Creating todo lists redirects to the todo list index page on success
     Failure/Error: clink_link "New Todo list"
     NoMethodError:
       undefined method `clink_link' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9f5abf4>
     # ./spec/features/todo_lists/create_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.25703 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo list index page on success

Is there something wrong with the versions, I'm using or something else? I've barely done anything so far and seem to come up with errors. I kindly appreciate for taking your time in responding as well Nick.

Anyone have a clue? I've been trying to figure this out for the past two days?

Hi:

There's a typo: it seems you wanted to use the click_link method, and you misspelled it instead.

Curious if you received an error. I'm seeing a failure with test as well. Here's 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") end

end

Ok! Got it to work;

When I ran the test the first time with only

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

The test came back perfect, 1 example, 0 failures.

Then, once I moved on and added

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

The test came back and failed, 1 example, 1 failure. Failed examples:

rspec ./spec/features/todo_lists/create_spec.rb:4 # Creating todo lists redirects to the todo list index page on success

Sound familiar? Everyone has gotten this error message it looks like.

All I did was DELETE the 2nd block of what we had just entered in...

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

Deleted it out of Sublime text, saved it, went back to terminal, pressed the UP key to re-run the test, and boom, once again it passed since it was the same test that past the first time...

Then went back to Sublime text, repasted the text we had just deleted, saved it, and re-ran again, and it worked!

Maybe something tricky with a bug, hope this works for everyone! I double-checked this and it seemed to work. Let me know!

Michael Baker
Michael Baker
5,709 Points

I'm getting the same failure and none of the above solutions resolve it.