Skip to content

Instantly share code, notes, and snippets.

@dadarek
Created November 15, 2013 19:15
Show Gist options
  • Save dadarek/7489976 to your computer and use it in GitHub Desktop.
Save dadarek/7489976 to your computer and use it in GitHub Desktop.
Dependency Injection Example
# 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