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 Writing Test Helpers

Writing Test: uninitialized constant TodoListHelpers (NameError) - Error

Is anyone else getting this error when inputting the

config.include TodoListHelpers, type: :feature

RSpec.configure do |config|
  config.include TodoListHelpers, type: :feature 
  config.expect_with :rspec do |expectations|
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

?

my support/todo_list_helpers.rb code:

module TodoListHelpers
    def visit_todo_list(list)
      visit "/todo_lists"
      within "#todo_list_#{todo_list.id}" do 
      click_link "List Items"
      end
    end
end

I noticed that we had to make some modifications different from the tutorial when we added rails helpers. Not sure if that's the reason.

5 Answers

Angel Israel Gallegos Espinoza
Angel Israel Gallegos Espinoza
3,096 Points

I think I know where you are wrong.

Look at the file: rails_helper.rb and be sure that this line:

#Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

is not commented

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Noel Worden
Noel Worden
3,639 Points

This worked for me. Thank you!

Thanks worked.

markd2
markd2
5,253 Points

Mixing list and todo_list as in Alexander's original code doesn't seem to effect the running of the code in any way.

What I found to work was requiring rails_helper in each _spec.rb file - that is, replacing require 'spec_helper' with 'rails_helper'.

rails_helper.rb contains: config.include TodoListHelpers, type: :feature

There is some code in spec_helper so I've required it in the rails_helper file (removing this requirement doesn't cause any errors at the moment but I'm leaving it in just in case.)

Also check that Dir[Rails.root.join...... is not still commented out in rails_helper.rb.

Steve Ono
Steve Ono
4,761 Points

Ok, I got it to work. Here is what worked for me:

In rails_helper.rb uncomment this: #Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

In rails_helper.rb, inside RSpec.configure do |config|, add this code: config.include TodoListHelpers, type: :feature

After that everything seems to be working properly.

Brandon Barrette
Brandon Barrette
20,485 Points

The error is in the 3rd line of your method:

def visit_todo_list(list)
      visit "/todo_lists"
      within "#todo_list_#{todo_list.id}" do 
        click_link "List Items"
      end
end

This line:

within "#todo_list_#{todo_list.id}" do 

Ruby doesn't know what todo_list.id is. Notice how you defined your function here:

def visit_todo_list(list)

Hope that makes sense. I didn't want to tell you what's wrong, but help you figure out how to troubleshoot your own code. Good luck!

thank you. not sure how i missed that ^^

but I'm still getting the same error regarding TodoListHelpers having uninitialized constant.

changed the within to

within "#todo_list_#{list.id}" do 

I got the same error and not sure what`s wrong.