We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

vanne on 01/21/07


Tagged

ruby


Versions (?)


assert_difference


Published in: Ruby 


URL: http://weblog.jamisbuck.org/2007/1/19/blocks-rock

A custom assertion that will allow you to pass a block to find the difference between two values.

  1. def assert_difference(object, method, difference=1)
  2. initial_value = object.send(method)
  3. yield
  4. assert_equal initial_value + difference, object.send(method)
  5. end

Report this snippet 

You need to login to post a comment.