Ruby 欢迎来到「TestTube」

cyri_ · June 21, 2021 · Last by cyri_ replied at June 23, 2021 · 752 hits

我要介绍 TestTube 🧪

这个简单的测试工具就是 Spectus 引擎。

实验代码

要使用 TestTube,需要一个匹配器。 例如,来自 Matchi,有一个集合。

现在,让我们使用这个自定义匹配器:

class BeTheAnswer
  def matches?
    expected.equal?(yield)
  end

  private

  def expected
    42
  end
end

让我们定义这个块:

block_of_code = -> { "101010".to_i(2) }

现在让我们看看结果:

require "test_tube"

experiment = TestTube.invoke(
  isolate: false,
  matcher: BeTheAnswer.new,
  negate: false,
  &block_of_code
)

experiment.actual # => 42
experiment.error  # => nil
experiment.got    # => true

成功!做得好!

谢谢你的阅读。

good job

Reply to tewboo

Thank you! ❤️

You need to Sign in before reply, if you don't have an account, please Sign up first.