diff options
| author | mo khan <mo@mokhan.ca> | 2014-05-21 17:06:22 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-05-21 17:06:22 -0600 |
| commit | c6e411fda561f7e80df131d5fa2edd1fc3e79b92 (patch) | |
| tree | 56d4220560ddd568bf659cf30fdbc38c4a7c4eaf | |
| parent | 3541bf182170f99962f4aa37b1111b3719e26d3c (diff) | |
create funny money.
| -rw-r--r-- | lib/float.rb | 6 | ||||
| -rw-r--r-- | lib/money.rb | 19 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 7 | ||||
| -rw-r--r-- | spec/unit/employee_spec.rb | 24 | ||||
| -rw-r--r-- | spec/unit/money_spec.rb | 17 |
5 files changed, 73 insertions, 0 deletions
diff --git a/lib/float.rb b/lib/float.rb new file mode 100644 index 0000000..a194c45 --- /dev/null +++ b/lib/float.rb @@ -0,0 +1,6 @@ +class Float + def dollars + Money.new(self) + end +end + diff --git a/lib/money.rb b/lib/money.rb new file mode 100644 index 0000000..6be9ec9 --- /dev/null +++ b/lib/money.rb @@ -0,0 +1,19 @@ +class Money + attr_reader :amount + + def initialize(amount) + @amount = amount + end + + def +(other_money) + Money.new(amount + other_money.amount) + end + + def ==(other_money) + amount == other_money.amount + end + + def eql?(other_money) + self == other_money + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69de29..4cc6251 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -0,0 +1,7 @@ +require "rubygems" +require 'bundler' +Bundler.require + +require 'money' +require 'float' + diff --git a/spec/unit/employee_spec.rb b/spec/unit/employee_spec.rb new file mode 100644 index 0000000..8996f5e --- /dev/null +++ b/spec/unit/employee_spec.rb @@ -0,0 +1,24 @@ +require "spec_helper" + +class Employee + def initialize + end + + def issue_grant(value_of_grant, share_price) + end + + def value_of_unvested_grants_at(price) + 0.00 + end +end + +describe Employee do + let(:sut) { Employee.new } + + context "when issued a grant that vests annually" do + it "computes the value of the grant after 6 months" do + sut.issue_grant(80_000, 1.00) + sut.value_of_unvested_grants_at(10.00).should == 0.00 + end + end +end diff --git a/spec/unit/money_spec.rb b/spec/unit/money_spec.rb new file mode 100644 index 0000000..b66e2a4 --- /dev/null +++ b/spec/unit/money_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe Money do + context "adding money" do + it "sum the money together" do + result = Money.new(10.00) + Money.new(10.00) + result.should == Money.new(20.00) + result.should eql(Money.new(20.00)) + end + end + + context "creating money" do + it "can be created from a float" do + 10.00.dollars.should == Money.new(10.00) + end + end +end |
