未定义的方法:assert_equal

时间:2014-11-29 06:06:33

标签: ruby unit-testing

我认为问题与我的测试类继承有关。我在SO上检查了几个其他线程,他们似乎都对不同的内在说法。一些固有的类包括: Minitest::Unit::TestCase Test::Unit::TestCase

固有的正确类是什么?还有别的我在这里做错了吗?谢谢! (;

require 'minitest/autorun'
require './any'

class TestAny < Minitest::Test
  describe "Any returns true" do
    items = [1, 2, 3, 4, 5]
    assert_equal items.any? { |item| item.even?}, true, "Some items are even"
  end
end

2 个答案:

答案 0 :(得分:4)

您似乎正在使用规范格式,但随后使用单元测试格式的匹配器。此外,如果您有describe块,则需要在其中设置it块。你试过这个吗?

describe "Any returns true" do
  it "Some items are even" do
    items.any? { |item| item.even?}.must_equal true
  end
end

答案 1 :(得分:0)

你可以写如下: -

require "minitest/autorun"

class TestAny < Minitest::Test
  def any_test
    items = [1, 2, 3, 4, 5]
    item_present = items.any? { |item| item.even? }

    assert_equal item_present, true, "Some items are even"
  end
end

这是测试运行: -

[arup@test]$ ruby test_any.rb
Run options: --seed 57100

# Running:



Finished in 0.001293s, 0.0000 runs/s, 0.0000 assertions/s.

0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
[arup@test]$