Skip to content

@zenspider /register.rb forked from postmodern/register.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
not hard and not terribly useful.
#!/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
@ivanoats

why is it not terribly useful?

@zenspider
Owner

Why is it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.