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

前端 未结 3 816
[愿得一人]
[愿得一人] 2021-02-06 21:34

I am writing my first unit tests with Test::Unit and I have reached a point where I need to compare two numbers. Much to my surprise, I have discovered that none of the followin

3条回答
  •  心在旅途
    2021-02-06 21:43

    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
    

提交回复
热议问题