Rspec-rails: Don't know how to build task 'spec:models' (see --tasks)

Created on 20 Jan 2017  ·  5Comments  ·  Source: rspec/rspec-rails

When running rake spec:models I get the error:

"Don't know how to build task 'spec:models' (see --tasks) "

Even though rake -AT produces:

...
rake spec # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers # Run the code examples in spec/controllers
rake spec:features # Run the code examples in spec/features
rake spec:helpers # Run the code examples in spec/helpers
rake spec:models # Run the code examples in spec/models
rake spec:prepare #
rake spec:statsetup #
...

Rails 5.0.1/Ruby 2.4/rspec-rails 3.5.1

I don't know if this is an rspec-rails issue, or a rake issue perhaps, or my own config issue??

Most helpful comment

@alexbrinkman did you add rspec-rails to your :development environment as well in your gem file? or just your :test environment?

If I have rspec-rails only in the :test group, then the rake tasks do not work. But if I move it to :development, :test they work correctly.

All 5 comments

I'd say somehow the rake task file isn't being detected by rake, what happens if you manually require 'rspec/rails/tasks/rspec.rake' in your Rakefile?

Here's what my Rakefile looks like after the change:

require_relative 'config/application'
require 'rspec/rails/tasks/rspec.rake'

Rails.application.load_tasks

But then just running the rake command gives:
LoadError: cannot load such file -- rspec/rails/tasks/rspec.rake

I'm using rvm and my gems are in a gemset, does that change what the path should be? Thanks for the help!

Drat, you probably need the full path to include the file as it's not a ruby file. I'm pretty sure this is an issue with how Rake and Rails are interacting to include the file though.

@alexbrinkman did you add rspec-rails to your :development environment as well in your gem file? or just your :test environment?

If I have rspec-rails only in the :test group, then the rake tasks do not work. But if I move it to :development, :test they work correctly.

@urkle - Thanks for the information, that worked. I added rspec-rails to my development group too. Previously it was just in test. Thanks so much!

Was this page helpful?
0 / 5 - 0 ratings