public
Last active — forked from postmodern/register.rb

not hard and not terribly useful.

  • 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#!/usr/bin/ruby -w
 
require 'rubygems'
require 'minitest/autorun'
 
# From: http://rubylearning.com/blog/2011/07/28/how-do-i-test-my-code-with-minitest/
 
class CashRegister
attr_reader :items
 
def initialize
@items = []
end
 
def scan(item)
@items << item
end
 
def total
@items.inject(0) {|sum, item| sum += item }
end
end
 
class MiniTest::Spec
attr_accessor :subject
 
def self.its msg, &block
it msg.to_s do
subject.send(msg).instance_eval &block
end
end
end
 
describe CashRegister do
before do
self.subject = CashRegister.new
end
 
describe "when empty" do
its(:items) { must_be_empty }
its(:total) { must_equal 0 }
end
 
describe "after scanning 1 and 2" do
before do
subject.scan(1)
subject.scan(2)
end
its(:items) { wont_be_empty }
its(:total) { must_equal 3 }
end
end

why is it not terribly useful?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.