Created
November 15, 2013 19:15
-
-
Save dadarek/7489976 to your computer and use it in GitHub Desktop.
Dependency Injection Example
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
# DEPENDENCY INJECTION | |
class A | |
def initialize(helper) | |
end | |
def doSomething | |
helper.someFunction | |
end | |
end | |
class B | |
def someFunction | |
end | |
end | |
# IN YOUR TESTS | |
class FakeB | |
attr_reader :returnValue | |
def someFunction | |
return returnValue | |
end | |
end | |
def someSpec | |
fake = B.new | |
fake.returnValue = 5 | |
a = A.new( fake ) | |
a.doSomething | |
a.should #assertion goes here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment