I would like to test if an instance variable lies in a range of numbers:
#part of the tested class
class Item
def initialize(value = 70 + rand(30))
@value = value
end
I tried the assertions in minitest assertions list but they didn't work. I solved the problem by using assert_in_delta as shown below:
#test_value.rb
class ValueTestCase < Test::Unit::TestCase
def test_if_value_in_range
item = Item.new
assert_in_delta(85, item.value, 15)
end
end
But would like to know if there is a formal assertion for this.
Another way would be to use Range#include?
:
assert_includes 70..100, p.value
assert(item.value.between?(70, 100))
assert((min..max) === result)
Works with Test::Unit.
assert_includes
is defined inMinitest::Assertions
, but I can't findassert_contains
. The link in your question also listsassert_includes
- Niklas B. 2012-04-04 18:04