public
Last active

Learning about minitest from Steve Klabnik

  • Download Gist
register.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
require 'minitest/autorun'
 
class TestCashRegister < MiniTest::Unit::TestCase
def setup
@register = CashRegister.new
end
def test_default_is_zero
assert_equal 0, @register.total
end
def test_total_calculation
@register.scan 1
@register.scan 2
assert_equal 3, @register.total
end
def test_total_is_zero_after_clear
@register.scan 1
@register.clear
assert_equal 0, @register.total
end
end
 
class CashRegister
def initialize
@items = []
end
def total
@items.inject(0, &:+)
end
def scan(item)
@items << item
end
def clear
@items = []
end
end

Thanks for sharing this code... :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.