Skip to content

Commit

Permalink
p.133 complexed outstanding(before refactoring)
Browse files Browse the repository at this point in the history
  • Loading branch information
kono committed May 11, 2010
1 parent e0ea9b8 commit 3a1facb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions chapter6/Extract_Method.rb
Expand Up @@ -16,9 +16,16 @@ def order_entry(amount)
@orders << Extract_Method_Order.new(amount)
end

def print_owing
def print_owing(previous_amount)
outstanding = previous_amount * 1.2

print_banner
outstanding = calculate_outstanding

# 勘定を計算(calculate outstanding)
@orders.each do |order|
outstanding += order.amount
end

print_details outstanding
end

Expand All @@ -35,7 +42,4 @@ def print_details(outstanding)
puts "amount: #{outstanding}"
end

def calculate_outstanding
@orders.inject(0.0){|result, order| result + order.amount }
end
end
4 changes: 2 additions & 2 deletions chapter6/TC_Extract_Method.rb
Expand Up @@ -25,12 +25,12 @@ def setup
must "test1" do
temp=Tempfile::new("foobar")
$stdout=temp
@obj.print_owing
@obj.print_owing(10)
$stdout=STDOUT
temp.close
temp.open
result= temp.read
expectation = "*************************\n***** Customer Owes *****\n*************************\nname: kono\namount: 60.0\n"
expectation = "*************************\n***** Customer Owes *****\n*************************\nname: kono\namount: 72.0\n"
temp.close
assert_equal(result, expectation)
end
Expand Down

0 comments on commit 3a1facb

Please sign in to comment.