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

Eliza SJ
Eliza SJ
4,587 Points

rspec error - undefined method

I keep getting this error when I run my test and I can't figure out how to fix it since I've checked and rechecked that I have the same exact wording in my create_spec.rb file as in the video...

there error is :

Users/Eliza/Desktop/ToDoApp/odot/spec/features/todo_lists/create_spec.rb:10:in `block in <top (required)>': undefined method `fill_in' for #<Class:0x007f855cbd6cd8> (NoMethodError)
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `module_eval'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:369:in `subclass'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:342:in `describe'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/dsl.rb:18:in `describe'
    from /Users/Eliza/Desktop/ToDoApp/odot/spec/features/todo_lists/create_spec.rb:3:in `<top (required)>'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
    from /Users/Eliza/.rvm/gems/ruby-2.2.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'```

3 Answers

Paul Weinert
Paul Weinert
13,698 Points

I ran into this problem as well with the visit method. It may or may not be the same problem.

Turned out that newer versions of rspec seem to create two helpers for you. spec_helper - which is auto required for every spec and then rails_helper - which looks very much the same as the spec_helper in the video.

I simply required rails_helper at the instead of spec_helper and everything worked out. Ruby 2.2, Rails 4.2

Good luck!

Can you post your create_spec please?

Steve.

Eliza SJ
Eliza SJ
4,587 Points

yes of course, sorry! it's:

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")
    end # remove this

    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")
    # add it here
end

Hi Eliza,

I'm not sure what's gone wrong there. The error is being thrown as the fill_in method isn't recognised. I think that's because it is outside of a test, i.e. an it do end block.

You can move the end that is part way down the code block to just above the last end and you'll be OK.

The test walks through creating a new todo list then adding an entry, ensuring that the output on the page reflects what is expected.

Give that a try (I've added comments in your code above) and let me know how you get on.

Steve.