ruby - MinitTest Spec 对第二个参数的混淆

标签 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".

出于某种原因,现在它显示“预期是汽油而不是柴油”。因此,添加我假设的消息参数(就像在测试单元版本中一样)似乎会使断言发生翻转。

规范框架中消息参数的想法是否无效?

最佳答案

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

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

gem install minitest

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

gem 'minitest'

关于ruby - MinitTest Spec 对第二个参数的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510955/

相关文章:

c++ - 通过使用 WIN32OLE 的 Ruby 的 C++ dll 的代码覆盖率

ruby-on-rails - 安装 minitest rails 后,rake test 没有做任何事情

javascript - ECMAScript 中的 "positive"和 "negative"是什么意思? +0 和 -0

ruby - Logstash过滤出嵌套json数组中的键的值为空的值

ruby-on-rails - 继承资源和CanCan 3层嵌套

ruby-on-rails - 当我在 Rails 中运行测试时,我该如何处理这个错误?

javascript - ECMAScript 规范 : meaning of question mark in the spec

XML 规范 : Union of xs:date, xs :gYearMonth, xs :gYear?

ruby-on-rails - Rails,数据结构和性能

ruby - Rails minitest BCrypt::Errors::InvalidHash: