|
Project Information
Featured
Links
|
amok (pronounced 'amok' not 'A Mok') is a user friendly mocking framework named after the signature dish of Cambodia. Examplevar mock = amok.Mock(MyClass);
mock.should_receive("getFoo").with_args("someValue", String, Number).times(3).and_return("foo")Why amok?The authors of amok built the framework out of necessity, although at the time of the first release there were already two mocking frameworks for JavaScript, which may be working out great for other teams we found that they weren't sufficient for the specific needs of our team and would find ourselves hand coding stubs for many of our spec and test writing requirements. We met our own personal requirements of a JavaScript mocking framework by implementing the following features and design principles: - Mock Callbacks amok allows your mocked methods to trigger callbacks, this allows ajax functionality to be mocked for easy testing and is very useful for teams working against web services which currently only exist on paper.
- Firebug integration amok has the option to either route mocking exceptions via firebug, the browser or both. By default it will throw via both if the firebug 'console' object has been detected by amok.
- Clean DSL - The default domain specific language for amok utilizes semantics popular in the behaviour driven development community and uses method chaining to make easy to remember mock declarations.
- Customizable DSL - With amok the underlying API is completely decoupled from the default DSL, this makes it easy to create custom mocking DSL's. This is especially useful for developers wishing to have the semantics of their JavaScript mocking framework match those of their serverside mocking framework.
- Regular expressions to extract public methods from the class constructor - Amok uses regular expressions to discover the public methods within the class constructor rather than by first instantiating the class and then looping through the instances members, which often causes exceptions to be raised when the code within constructor is expecting an argument which was never received.
- Easy on your namespace - The entire framework is accessed from the 'amok' namespace, so as long as you have no existing variable called 'amok' within your namespace \you are good to go, if you have then it's a simple case of doing a search/replace on the amock.js file to replace all instances of 'amok' with a namespace of your choosing.
- No need for dependency injection - Amok allows the mocking of constructors, this means a class that has a dependency on the constructor can be tested in isolation without the need for dependency injection.
|