Monkey Patching Dependency Injector
Want to see pretty graphs? Log in now!
npm install monkey-patch
|1||downloads in the last day|
|5||downloads in the last week|
|9||downloads in the last month|
|Last Published By|
|Version||0.0.3 last updated 2 years ago|
|Keywords||dependency, injection, monkey|
patching dependent functionality into objects. Dependency Injection (DI) is a
concept that allows components, such database access, to be swapped in/out
during run time instead of compile time.
This allows an application to change its functionality without changing its logic. This is very useful when testing an application, being able to swap in a database component for a fake on that writes to nowhere.
monkey provides two core functions:
Here is an example where
monkey being used to inject functionality for a test
class User save: () -> # real functionality find: (id) -> # look up the user user = new User monkey.patch user, save: () -> true find: () -> new User ... run some tests ... # revert user back to normal monkey.unpatch user # do some other change to user monkey.patch user, save: () -> false find: () -> null ... etc ..