Loading models in rspec feature tests

Hey,

I was running through the Test Driven Rails trail, and in the fourth video, “Signing In…” about 19mins in, Josh puts

    ToDo.create!(title: "Buy milk", email: "someone-else@example.com")

in the spec, but when I run this I’m getting

     Failure/Error: ToDo.create!(title: "Buy milk", email: "someone-else@example.com")

     NameError:
       uninitialized constant ToDo
     # ./spec/features/user_sees_own_todos_spec.rb:5:in `block (2 levels) in <top (required)>'

I’m using Rails 5.0.2, and guessing it’s something to do with the version differences, but not sure how to fix it.

How do you load/add the model into the spec, I’ve googled a bunch of things for this, but they all seem to point to the require 'rails_helper' which is already in the spec.

Any suggestions would be awesome.

It should be loaded automatically. Check that your model is named “ToDo” and not “Todo”.

Otherwise, push your repo up to GitHub and I can take a look.

1 Like

The tiniest thing :blush:

You’re bang on the money and I can’t believe I didn’t spot it. ToDo instead of Todo

Thanks Andy.