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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s