简体   繁体   中英

No MiniTest rake tasks in rails 4

I am trying to create a new Rails 4.1.4 app (Ruby 2.1.2) utilizing minitest. After following the instructions shown below, when I run rake -T it does not show any minitest rake tasks.

Is there something I am missing here?

1) Add to Gemfile

group :test do
  gem 'minitest-rails'
  gem 'minitest-rails-capybara'
  gem 'minitest-colorize'
  gem 'minitest-focus'
end

2) bundle

3) Add to test/test_helper.rb (after require "rails/test_help" )

require 'minitest/rails'
require 'minitest/rails/capybara'
require 'minitest/focus'
require 'minitest/colorize'

4) Remove require 'rails/all' from config/application.rb

5) Add to config/application.rb

require "active_record/railtie"
require "action_controller/railtie"
require 'rake/testtask'
require "action_mailer/railtie"
require "sprockets/railtie"
require "minitest/rails/railtie"

I then run rake -T and it comes back with a list of rake tasks which does not include any minitest tasks.

Since 2.0 minitest-rails does not add minitest rake tasks. The default rails test rake tasks are used. See the section on running tests in the README .

Also, if you are including the minitest-rails Railtie in your config/application.rb , then you shouldn't place the dependency in the :test group in your Gemfile .

I am a bit confused about your question. Are you trying to add custom minitest tasks, or just normal ones such as rake test? Rails 4 should already come with minitest as a dependency for ActiveSupport. In your Gemfile.lock file, check to make sure if minitest is under activesupport. Mine looks like this:

activesupport (4.1.0)
  i18n (~> 0.6, >= 0.6.9)
  json (~> 1.7, >= 1.7.7)
  minitest (~> 5.1)

If not, try running bundle install to see if all the dependencies are installed.

Finally, (though you probably know this) the tasks won't say minitest. They will be 'test', like 'rake test', so if that's what you're confused about (I can't really tell based on the question) then just make sure rake test works and you're good to go.

Maybe since you put gem 'minitest-rails' in the test group, and rake by default sets RAILS_ENV=development , you need to do something like:

RAILS_ENV=test bundle exec rake -T

or just take gem 'minitest-rails' out of the test group, since the line require "minitest/rails/railtie" in application.rb will always try to load it anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM