Ruby:为什么我用 Test::Unit 运行测试时没有显示点? [英] Ruby: Why are no dots showing when I run tests with Test::Unit?

查看:21
本文介绍了Ruby:为什么我用 Test::Unit 运行测试时没有显示点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 Ruby 的 Test::Unit::TestCase,虽然我的测试会运行、通过、失败等等.我没有看到每个测试输出的点 -案件.这是我需要设置的配置,还是我需要指定的详细程度?

I'm playing around with Ruby's Test::Unit::TestCase, and though my tests will run, pass, fail, etc. I'm not seeing the dots outputted for each test-case. Is this a configuration I need to set, or a level of verbosity I need to specify?

我正在运行 Ruby 2.1.0p0

I'm running Ruby 2.1.0p0

作为参考,这是我正在使用的代码.它来自 Destroy All Software 截屏视频,其中练习是从头开始构建 rspec(当然不是全部):

For reference, here's the code I'm working with. It's from a Destroy All Software screencast where the exercise is to build rspec from scratch (not the whole thing, of course):

测试:

#test_spec.rb

require 'test/unit'
require_relative 'spec'


class TestDescribe < Test::Unit::TestCase
  def test_that_it_can_pass
    describe 'some thing' do
      it 'has some property' do
      end
    end
  end

  def test_that_it_can_fail
    assert_raise(IndexError) do
      describe 'some failing thing' do 
        it 'fails' do
          raise IndexError
        end
      end
    end
  end
end


class TestAssertion < Test::Unit::TestCase
  def test_that_it_can_pass
    2.should == 2
  end

  def test_that_it_can_fail
    assert_raise(AssertionError) do
      1.should == 2
    end
  end
end

和代码:

#spec.rb

def describe(description, &block)
  ExampleGroup.new(block).evaluate!
end


class ExampleGroup
  def initialize(block)
    @block = block
  end

  def evaluate!
    instance_eval(&@block)
  end

  def it(description, &block)
    block.call
  end
end


class Object
  def should
    DelayedAssertion.new(self)
  end
end

class DelayedAssertion
  def initialize(subject)
    @subject = subject
  end

  def ==(other)
    raise AssertionError unless @subject == other
  end
end


class AssertionError < Exception
end

使用 ruby test_spec.rb

Run options:

# Running tests:

Finished tests in 0.004410s, 907.0295 tests/s, 453.5147 assertions/s.
4 tests, 2 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]

推荐答案

我升级了 'test-unit' 并恢复了原状.在撰写本文时,版本为 3.1.8.

I upgraded 'test-unit' and I got the dots back. At the moment of writing this the version is 3.1.8.

这篇关于Ruby:为什么我用 Test::Unit 运行测试时没有显示点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆