MinitTest Spec混淆第二个参数

时间:2012-11-22 10:42:42

标签: ruby minitest specifications

我是BDD的新手,我正在尝试使用MiniTest Spec:

require 'minitest/spec'
require 'minitest/autorun'

class Car
  attr_accessor :type

  def initialize(type)
    @type = 'petrol'
  end
end


describe Array do 
  it "must be diesel" do
    Car.new('diesel').type.must_equal 'diesel'
  end
end

这很棒 - 运行它我得到以下输出:

Failure:
test_0001_must_be_diesel(ArraySpec):
Expected "diesel", not "petrol".

这是有道理的 - “预期的柴油,而不是汽油”正是我所期待的。如果我在我的must_equal语句中放置第二个参数(我假设它是我想要在失败时返回的消息) - 我得到一个奇怪的结果:

require 'minitest/spec'
require 'minitest/autorun'

class Car
  attr_accessor :type

  def initialize(type)
    @type = 'petrol'
  end
end


describe Array do 
  it "must be diesel" do
    Car.new('diesel').type.must_equal 'diesel', 'it must be a diesel'
  end
end

运行这个我得到:

1) Failure:
test_0001_must_be_diesel(ArraySpec):
it must be a diesel.
Expected "petrol", not "diesel".

出于某种原因,现在它说“预期的汽油不是柴油”。因此,似乎添加我假设的消息参数(因为它在测试单元版本中)正在使断言翻转。

推测框架中的消息参数的概念是否为空?

1 个答案:

答案 0 :(得分:2)

MiniTest :: Spec处理多个参数的方式存在一些不一致之处。它似乎已在https://github.com/seattlerb/minitest/commit/cd4fe89b0057edc2258876ad8c5f5e7e722f73c2中修复。

只需从RubyGems安装最新版本的MiniTest,你就可以了:

gem install minitest

然后将其添加到文件顶部以使用gem:

gem 'minitest'
相关问题