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

Kota Fukada
Kota Fukada
16,243 Points

Got error with spec/models/todo_item_spec.rb

When I type /Users/macuser/.rbenv/shims/rspec spec/models/todo_item_spec.rb , I got error message. And I can't figure it out....

/Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in load': cannot load such file -- /Users/macuser/spec/models/todo_item_spec.rb (LoadError) from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:inblock in load_spec_files' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in each' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:inload_spec_files' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in setup' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:inrun' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in run' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:ininvoke' from /Users/macuser/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rspec-core-3.4.4/exe/rspec:4:in <top (required)>' from /Users/macuser/.rbenv/versions/2.3.0/bin/rspec:23:inload' from /Users/macuser/.rbenv/versions/2.3.0/bin/rspec:23:in `<main>'

Kota Fukada
Kota Fukada
16,243 Points

This is my todo_item_spec.rb.

require 'rails_helper'

RSpec.describe TodoItem, type: :model do it { should belong_to(:todo_list) } end

3 Answers

This is what fixed it for me https://github.com/thoughtbot/shoulda-matchers#rspec I just commented out what I didn't need. This left me with just the rspec framework and library rails.

Todd MacIntyre
Todd MacIntyre
12,248 Points

Roll back your version of shoulda matchers to that which is used in Jason's video. Put this into your gemfile in the group :test section:

gem 'shoulda-matchers', '~> 2.4.0'

and then re-bundle your gemfiles by going into the odot directory in your console and entering:

bundle
Todd MacIntyre
Todd MacIntyre
12,248 Points

Check the output from bundler to ensure that version 2.4.* is being used.

Jeff Wolfram
Jeff Wolfram
10,490 Points

I am having the same problem. I typed in

require 'spec_helper'

describe TodoItem do
 it { should belong_to(:todo_list) }

end

It then started throwing the error Failures:

1) TodoItem Failure/Error: it {should belong_to(:todo_list) } NoMethodError: undefined method belong_to' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f80699890b8> # ./spec/models/todo_item_spec.rb:4:inblock (2 levels) in <top (required)>'

Finished in 0.00107 seconds 1 example, 1 failure

Failed examples:

rspec ./spec/models/todo_item_spec.rb:4 # TodoItem

Did you have any luck figuring it out?