April 2016
Intermediate to advanced
222 pages
4h 30m
English
Ruby's mixin functionality can be very useful. Modules can group together useful features that can be added at runtime to any class. However, given the dynamic nature of Ruby, testing the mixin features of a module can be tricky.
Let's go back to the AddressValidator module we worked with in previous sections of this chapter and in Chapter 1, Exploring Testability from Unit Tests to Behavior-Driven Development and Chapter 2, Specifying Behavior with Examples and Matchers. We want to make this module into a mixin that we can add to any object with an address method. Then we can call address_valid? on the object to trigger all the validations.
Regardless of the complexity of the metaprogramming involved with a ...
Read now
Unlock full access