assert_change and assert_no_change for Test::Unit + Minitest inspired by RSpec

Usage

@updated_at = lambda{ @model.updated_at.to_i }
assert_change(@updated_at) { @model.touch }
assert_no_change(@updated_at) { @model.reload }

Code

  def assert_change(what)
    old = what.call
    yield
    assert_not_equal old, what.call
  end

  def assert_no_change(what)
    old = what.call
    yield
    assert_equal old, what.call
  end

Leave a comment