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 Relationships

Brian Patterson
Brian Patterson
19,588 Points

Not sure why this is failing.

I don't know why this is failing when I put the following command in the console bin/rspec spec/models/todo_list_spec.rb

Failures:

  1) TodoList should have many :todo_items
     Failure/Error: it { should have_many(:todo_items) }
     NoMethodError:
       undefined method `has_many?' for #<TodoList:0xbb3f87b4>
     # ./spec/models/todo_list_spec.rb:4:in `block (2 levels) in <top (required)>'

Finished in 0.01068 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/models/todo_list_spec.rb:4 # TodoList should have many :todo_items

Randomized with seed 37388

Looking at the forum I am supposed to do a configuration for 3.0 . But as always no one has explained (least of all Jason) where to put in the spec_helper.rb

1 Answer

Alvin Phun
Alvin Phun
15,468 Points

Hey Brian,

Not sure if you've resolved this yet, but place the following code at the bottom of your spec_helper.rb, AFTER the RSpec.configure block.

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end
Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

This worked for me, but also including

require 'shoulda/matchers'

in the rspec_helper.rb