我的rails测试会产生乱码输出

时间:2016-11-09 16:53:26

标签: ruby-on-rails ruby ruby-on-rails-3

我刚刚超越了一个新项目,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

screenshot of the tests running

.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 个答案:

答案 0 :(得分:1)

摆脱警告的三个(其他)选项:

  1. 降级Ruby直到警告消失。您使用的是在Ruby 2.2之前创建的旧版Rails。 {2}在Ruby 2.2之前的某个时候被弃用。

  2. 手动编辑gem存储库中的违规行。

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

  4. ......当然还有最后的选择:升级Rails。