Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add memoized subject

  • Loading branch information...
commit 5a0020447f2d0101baf251d7070be6944409bfb5 1 parent 76eecef
@dchelimsky authored
View
BIN  RSpecTipsAndTricks.key
Binary file not shown
View
2  code/implicit_subject/account_spec.rb
@@ -8,6 +8,6 @@
end
context "when first created" do
- it { should have_a_balance_of(Money.new(0, :BLR))}
+ it { should have_a_balance_of(0, :BLR)}
end
end
View
6 code/lib/account.rb
@@ -5,11 +5,15 @@ class Account
def initialize(amount=nil, currency=nil)
if amount && currency
- @balance = Money.new(amount, currency)
+ deposit(amount, currency)
else
@balance = Money.new(0, :BLR)
end
end
+
+ def deposit(amount, currency)
+ @balance = Money.new(amount, currency)
+ end
def inspect
"Account (#{balance.inspect})"
View
10 code/memoized_subject/account_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Account do
+ context "with a zero balance" do
+ it "accepts deposits" do
+ subject.deposit(12, :USD)
+ subject.should have_a_balance_of(12, :USD)
+ end
+ end
+end
View
4 code/spec/support/matchers.rb
@@ -1,6 +1,6 @@
-Spec::Matchers.define :have_a_balance_of do |money|
+Spec::Matchers.define :have_a_balance_of do |amount, currency|
match do |account|
- account.balance == money
+ account.balance == Money.new(amount, currency)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.