Skip to content

Instantly share code, notes, and snippets.

@gsinclair
Created October 15, 2009 13:26
Show Gist options
  • Save gsinclair/210946 to your computer and use it in GitHub Desktop.
Save gsinclair/210946 to your computer and use it in GitHub Desktop.
Demonstrates use of Object#tap in unit testing. Small gain in neatness.
class TestTriangle < Test::Unit::TestCase
def test_isosceles_given_base_and_height
triangle(:ABC, :isosceles, :base => 5, :height :=> 9).tap do |t|
assert_point_equal p(2.5,9), t.apex
assert_point_equal p(0,0), @register[:A]
assert_point_equal p(5,0), @register[:B]
assert_point_equal p(2.5,9), @register[:C]
assert_equal t, @register.retrieve(:triangle, :ABC)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment