1

我正在使用 Minitest 和 Turn gem 来获得漂亮的测试输出。但是当我在 Watchr 中运行测试时,没有一种颜色会延续。所以我得到了所有漂亮的间距和格式,但没有红色/绿色编码。我需要做些什么来设置它吗?

这是我的 .watchr 文件

# [PROGRESS|DOT]=true bundle exec watchr test/tests.watchr

ENV["WATCHR"] = "1"
system 'clear'

def growl(message)
  if growlnotify = `which growlnotify`.chomp
    title = "Somebody's Waaaatchin Meeeee...."
    image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
    options = "-n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
    system %(#{growlnotify} #{options} &)
  end
end

def run(cmd)
  puts(cmd)
  `#{cmd}`
end

def run_test_file(file)
  system('clear')
  result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
  growl result.split("\n").last rescue nil
  puts result
end

def run_all_tests
  system('clear')
  result = run "rake test"
  growl result.split("\n").last rescue nil
  puts result
end

def run_all_features
  system('clear')
  run "cucumber"
end

def related_test_files(path)
  Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ }
end

def run_suite
  run_all_tests
  run_all_features
end

watch('test/test_helper\.rb') { run_all_tests }
watch('test/.*/.*_test\.rb') { |m| run_test_file(m[0]) }
watch('app/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
watch('features/.*/.*\.feature') { run_all_features }

# Ctrl-\
Signal.trap 'QUIT' do
  puts " --- Running all tests ---\n\n"
  run_all_tests
end

@interrupted = false

# Ctrl-C
Signal.trap 'INT' do
  if @interrupted then
    @wants_to_quit = true
    abort("\n")
  else
    puts "Interrupt a second time to quit"
    @interrupted = true
    Kernel.sleep 1.5
    # raise Interrupt, nil # let the run loop catch it
    run_suite
  end
end

还有我的 Gemfile,如果你在乎的话:

group :development do
  # Deployment
  gem 'sunspot_solr'
  gem 'brakeman', :require=>false

  # Capistrano requires...
  gem 'net-scp', :require=>false
  gem 'net-sftp', :require=>false
  gem 'highline', :require=>false
  gem 'net-ssh-gateway', :require=>false
  gem 'capistrano', :require => false
  gem 'capistrano_colors', :require => false

  # Tests auto-run on save
  gem 'guard', '~> 0.8.0'
  gem 'guard-livereload'

  gem 'watchr' # because guard doesn't reload my code

  # Sugary goodness
  gem 'annotate', :require => false, :git => 'git://github.com/jeremyolliver/annotate_models.git', :branch => 'rake_compatibility'
end

group :test do
  # Mocking
  gem 'vcr', :require=>false
  gem 'webmock', :require=>false

  # Testing framework
  gem 'factory_girl_rails', :require => false
  gem 'turn', '>= 0.9.3'
  gem 'minitest'                      # At least v2.0.2 if using MiniShoulda.
  gem 'guard-minitest'
  gem 'mini_specunit'                 # The goods! Force MiniTest::Spec instead of MiniTest::Unit.
  gem 'mini_backtrace'                # Use Rails.backtrace_cleaner with MiniTest.
  gem 'mini_shoulda'                  # A small Shoulda syntax on top of MiniTest::Spec.
  gem 'mocha'                         # For the occasional black box test.
  gem 'simplecov', :require => false  # Test coverage in Ruby 1.9
  # Spork makes our tests faster
  gem 'spork', git: 'https://github.com/sporkrb/spork.git' #'~> 0.9.0.rc9'
  gem 'guard-spork'
  gem 'spork-testunit', git: 'git://github.com/sporkrb/spork-testunit.git'
  gem 'ruby-prof' # needed to make Spork run on Minitest?
end
4

0 回答 0