forked from tutsplus/ruby-refactoring
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f59d6c
commit d412059
Showing
4 changed files
with
96 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.pattern = 'test/*test.rb' | ||
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,32 @@ | ||
class Client | ||
attr_reader :clerk | ||
|
||
def initialize clerk | ||
@clerk = clerk | ||
end | ||
end | ||
|
||
class Clerk | ||
attr_reader :department | ||
|
||
def initialize (department) | ||
@department = department | ||
end | ||
|
||
def manager | ||
department.manager | ||
end | ||
end | ||
|
||
class Manager | ||
attr_accessor :department | ||
end | ||
|
||
class Department | ||
attr_reader :manager | ||
def initialize manager | ||
@manager = manager | ||
|
||
manager.department = self | ||
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,33 @@ | ||
class Client | ||
attr_reader :department, :clerk | ||
|
||
def initialize department, clerk | ||
@department = department | ||
@clerk = clerk | ||
end | ||
end | ||
|
||
class Manager | ||
attr_accessor :department | ||
end | ||
|
||
class Clerk | ||
attr_reader :department | ||
|
||
def initialize(department) | ||
@department = department | ||
end | ||
|
||
def manager | ||
department.manager | ||
end | ||
end | ||
|
||
class Department | ||
attr_reader :manager | ||
def initialize manager | ||
@manager = manager | ||
|
||
manager.department = self | ||
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,26 @@ | ||
require 'minitest/spec' | ||
require 'minitest/autorun' | ||
|
||
require 'before' if ENV["BEFORE"] | ||
require 'after' unless ENV["BEFORE"] | ||
|
||
describe Client do | ||
let(:manager) { Manager.new } | ||
let(:department) { Department.new(manager) } | ||
let(:clerk) { Clerk.new(department) } | ||
|
||
if ENV["BEFORE"] | ||
it "wants to know about the manager through a department" do | ||
client = Client.new(department, clerk) | ||
|
||
client.department.manager.wont_be_nil | ||
end | ||
|
||
else | ||
it "should rather be guided by a clerk to access that info" do | ||
client = Client.new(clerk) | ||
|
||
client.clerk.manager.wont_be_nil | ||
end | ||
end | ||
end |