-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
・5.2 通知を受けるよりよい方法 EFROR-62
- Loading branch information
Showing
4 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module DesignPattern | ||
module Observer | ||
class TaxMan | ||
def update( changed_employee ) | ||
puts("#{changed_employee.name}に新しい税金の請求書を送ります!") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rails_helper' | ||
|
||
describe DesignPattern::Observer::Employee do | ||
describe '#salary' do | ||
it 'observe payroll' do | ||
fred = DesignPattern::Observer::Employee.new('Fred', 'Crane Operator', 30000) | ||
payroll = DesignPattern::Observer::Payroll.new | ||
fred.add_observer( payroll ) | ||
|
||
expected = <<-EOS | ||
Fredのために小切手を切ります! | ||
彼の給料はいま35000です! | ||
EOS | ||
|
||
expect { fred.salary = 35000 }.to output(expected).to_stdout | ||
end | ||
|
||
it 'observe payroll and tax man' do | ||
fred = DesignPattern::Observer::Employee.new('Fred', 'Crane Operator', 30000) | ||
payroll = DesignPattern::Observer::Payroll.new | ||
fred.add_observer( payroll ) | ||
tax_man = DesignPattern::Observer::TaxMan.new | ||
fred.add_observer( tax_man ) | ||
|
||
expected = <<-EOS | ||
Fredのために小切手を切ります! | ||
彼の給料はいま90000です! | ||
Fredに新しい税金の請求書を送ります! | ||
EOS | ||
|
||
expect { fred.salary = 90000 }.to output(expected).to_stdout | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.