module MiniTest::Assertions

Public Instance Methods

assert_count(value, list) click to toggle source
# File lib/minitest_rails_tools/expectations.rb, line 5
def assert_count(value, list)
  size = list.size
  assert_equal value, size, "Expected size to be #{value}, but was #{size}"
end
assert_difference(expression, difference = 1, message = nil) { || ... } click to toggle source
# File lib/minitest_rails_tools/expectations.rb, line 17
def assert_difference(expression, difference = 1, message = nil, &block)
  expressions = Array.wrap expression
  exps = expressions.collect do |e|
    e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
  end
  before = exps.collect(&:call)

  yield

  expressions.zip(exps).each_with_index do |(code, e), i|
    error  = "#{code.inspect} didn't change by #{difference}"
    error  = "#{message}.\n#{error}" if message
    assert_equal(before[i] + difference, e.call, error)
  end
end
assert_same_elements(value, list) click to toggle source
# File lib/minitest_rails_tools/expectations.rb, line 10
def assert_same_elements(value, list)
  assert_equal(
    list.sort, value.sort,
    "Expected #{list} to have the same elements as #{value}"
  )
end