Test::Unit Rails - How to assert one number is greater than another one?

蓝咒 提交于 2019-12-03 04:13:12

Rather than provide a bunch of different assertions as you suggest, Test::Unit provides the method assert_operator, used like this:

assert_operator x, :>, y
assert_operator x, :>=, y
etc. 

How about this simple thing,

assert x>y

Here are some functions you can put in test/test_helper.rb

  def assert_gt(a, b)
    assert_operator a, :>, b
  end

  def assert_gte(a, b)
    assert_operator a, :>=, b
  end

  def assert_lt(a, b)
    assert_operator a, :<, b
  end

  def assert_lte(a, b)
    assert_operator a, :<=, b
  end

Then call like so:

assert_gt 6, 3
assert_gte 5, 5
assert_lt 4, 5
assert_lte 5, 5
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!