metaskills / minitest-spec-rails

:bento: Make Rails Use MiniTest::Spec!

Home Page:http://github.com/metaskills/minitest-spec-rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails 3.2: empty test is ran after every rake command

samgavinio opened this issue · comments

In a fresh rails 3.2 app, with the environment set to test, every rake command executes an empty test suite which is weird. This has some nasty side-effects in most CI pipelines where you have to call stuff like rake db:test:prepare.

RAILS_ENV=test bundle exec rake about

About your application's environment
Ruby version              2.3.0 (x86_64-darwin15)
RubyGems version          2.5.1
Rack version              1.4.7
Rails version             3.2.22.4
JavaScript Runtime        Node.js (V8)
Active Record version     3.2.22.4
Action Pack version       3.2.22.4
Active Resource version   3.2.22.4
Action Mailer version     3.2.22.4
Active Support version    3.2.22.4
Middleware                ActionDispatch::Static, Rack::Lock, ...
Application root          /file/path
Environment               test
Database adapter          mysql2
Database schema version   0
Run options: --seed 11739

# Running tests:


Finished tests in 0.000323s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Reproduction Steps

  • Make sure you have rails 3.2
  • Create a new rails app
  • Add the following gems to the test group of your Gemfile
gem 'test-unit'
gem "minitest", "~> 4"
gem 'minitest-spec-rails', '~> 4.7'
  • Execute any rake command with the environment set to test, e.g RAILS_ENV=test bundle exec rake about

For reference my default rakefile is just

#!/usr/bin/env rake
require File.expand_path('../config/application', __FILE__)

Rails3::Application.load_tasks

I ended up here from guard/guard-minitest#73

bundle show output is

bundle show
Gems included by the bundle:
  * actionmailer (3.2.22.4)
  * actionpack (3.2.22.4)
  * activemodel (3.2.22.4)
  * activerecord (3.2.22.4)
  * activeresource (3.2.22.4)
  * activesupport (3.2.22.4)
  * arel (3.0.3)
  * builder (3.0.4)
  * bundler (1.15.0)
  * coffee-rails (3.2.2)
  * coffee-script (2.4.1)
  * coffee-script-source (1.12.2)
  * erubis (2.7.0)
  * execjs (2.7.0)
  * hike (1.2.3)
  * i18n (0.8.4)
  * journey (1.0.4)
  * jquery-rails (3.1.4)
  * json (1.8.6)
  * mail (2.5.4)
  * mime-types (1.25.1)
  * minitest (4.7.5)
  * minitest-spec-rails (4.7.10)
  * multi_json (1.12.1)
  * mysql2 (0.3.18)
  * polyglot (0.3.5)
  * power_assert (0.2.6)
  * rack (1.4.7)
  * rack-cache (1.7.0)
  * rack-ssl (1.3.4)
  * rack-test (0.6.3)
  * rails (3.2.22.4)
  * railties (3.2.22.4)
  * rake (12.0.0)
  * rdoc (3.12.2)
  * sass (3.4.24)
  * sass-rails (3.2.6)
  * sprockets (2.2.3)
  * test-unit (3.1.5)
  * thor (0.19.4)
  * tilt (1.4.1)
  * treetop (1.4.15)
  * tzinfo (0.3.53)
  * uglifier (3.2.0)

Removing require 'minitest/autorun' in

require 'minitest/autorun'
, resolves the problem but I'm not familiar enough with this gem to know what side effects that has.

Have you made sure to do this in your Gemfile?

group :test do
  gem 'minitest-spec-rails', '~> 4.7'
end

Hi 👋 @metaskills, yes, here is the Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.22.4'
gem 'mysql2', '0.3.18'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'test-unit'

group :test do
  gem "minitest", "~> 4"
  gem 'minitest-spec-rails', '~> 4.7'
end

gem 'jquery-rails'

OK... so I have seen this before in 3.2 and it did bother me as well, more so when I saw it in the development env which is fixed by putting the gem in the test group. The db:test:prepare task does load the test env. That task is invoked for you automatically when you run the test task, so you I normally don't find complaints for this and I just ignored it in 3.2.

Pretty sure Rails 4.x. See this commit where we removed that line. 2084499

Maybe this too would work in the 3-x-stable branch. You could delete it and make a PR to our 3-x-stable branch and see what Travis says.

Resolved in 4.7.11. Thanks @metaskills !