我的 rails 测试产生乱码输出

My rails tests produce gibberish output

我刚刚接管了一个新项目,rake test 产生了很多乱码输出。为什么会这样?我尝试删除所有我不知道的宝石,但我的输出仍然模糊不清。我通过 bundle exec rake test.

调用测试套件

示例输出 - 它是此类内容的页面。

/Users/hendricius/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.22.5/lib/active_support/file_update_checker.rb:98: warning: File.exists? is a deprecated name,
use File.exist? instead
/Users/hendricius/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.22.5/lib/active_support/file_update_checker.rb:98: warning: File.exists? is a deprecated name,
use File.exist? instead
/Users/hendricius/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.22.5/lib/active_support/file_update_checker.rb:98: warning: File.exists? is a deprecated name,
use File.exist? instead
/Users/hendricius/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.22.5/lib/active_support/file_update_checker.rb:98: warning: File.exists? is a deprecated name,
use File.exist? instead

.ruby-version 文件中的 ruby 版本是 2.2.2。安装的 rails 版本是 3.2.22.5.

我的测试宝石是:

group :test, :development do
  # gem 'rack-mini-profiler'
  # gem 'minitest'
  gem 'minitest-rails'
  gem 'test-unit'
  gem 'shoulda'
  gem 'shoulda-matchers'
  gem 'fabrication'
  gem 'byebug'
end

然后我仔细检查了我的 Rakefile。它具有以下内容:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

WooWoop::Application.load_tasks

task default: [:test]

我唯一能想到的就是我的 test_helper。我粘贴了下面的内容。看起来不错。

ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
require "minitest/pride"
require 'shoulda'
require 'shoulda/matchers'
# $VERBOSE=nil

# ActiveRecord::Migration.check_pending!
ActiveSupport::TestCase.test_order = :random
# Protractor test or even some dirty debugging in the rails console on test environment
# might have left some garbage on the DB. Lets make sure we start with a clean state.
# parses the response and returns it.

让输出静音的唯一方法是使用 RUBYOPT=W0 TEST=test/unit/shop_test.rb be rake test。自从我还在使用 rails 3 以来,这是唯一的方法吗?

更新:

我现在尝试降级到 ruby 2.0.0

我仍然收到很多以前从未见过的奇怪警告。

/Users/hendricius/.rbenv/versions/2.0.0-p648/lib/ruby/gems/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:89: warning: instance variable @mount_on not in
itialized
/Users/hendricius/.rbenv/versions/2.0.0-p648/lib/ruby/gems/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:243: warning: instance variable @previous_model_for_showcase_cov
er_picture not initialized
/Users/hendricius/.rbenv/versions/2.0.0-p648/lib/ruby/gems/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:89: warning: instance variable @mount_on not in
itialized
/Users/hendricius/.rbenv/versions/2.0.0-p648/lib/ruby/gems/2.0.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:243: warning: instance variable @previous_model_for_manager_pict
ure not initialized
(eval):11: warning: instance variable @opening_hours_monday_from not initialized
(eval):2: warning: instance variable @opening_hours_monday_to not initialized
(eval):11: warning: instance variable @opening_hours_tuesday_from not initialized
(eval):2: warning: instance variable @opening_hours_tuesday_to not initialized
(eval):11: warning: instance variable @opening_hours_wednesday_from not initialized
(eval):2: warning: instance variable @opening_hours_wednesday_to not initialized
(eval):11: warning: instance variable @opening_hours_thursday_from not initialized
(eval):2: warning: instance variable @opening_hours_thursday_to not initialized
(eval):11: warning: instance variable @opening_hours_friday_from not initialized
(eval):2: warning: instance variable @opening_hours_friday_to not initialized
(eval):11: warning: instance variable @opening_hours_saturday_from not initialized
(eval):2: warning: instance variable @opening_hours_saturday_to not initialized

编辑:

我最终升级到 rails 4。所有警告都消失了。

消除警告的三个(其他)选项:

  1. 降级 Ruby 直到警告消失。您使用的是 Rails 的旧版本,它是在 Ruby 2.2 之前创建的。 File.exists? 在 Ruby 2.2.

  2. 之前的某个时间被弃用
  3. 手动编辑 gem 存储库中的违规行。

  4. 运行 大量搜索并替换 gem 存储库中的 shell 命令:
    https://superuser.com/questions/428493/how-can-i-do-a-recursive-find-and-replace-from-the-command-line

...当然还有最后一个选项:升级 Rails.