8. Debugging with Ruby
Activity 8.01: Perform Debugging on a Voting Application
Solution
- First up, let's write a simple test to ensure that our
Controllerclass does indeed have access to the instantiatedLoggerclass defined in theLoggerControllerinitializer:tests/test_controller.rb def test_controller_logger   t = Time.now   machine = VotingMachine.new(t.month, t.year)   controller = Controller.new(machine)   assert_instance_of(Logger,            controller.instance_variable_get('@logger')) end - Next, let's extend our
ControllerLoggermodule. We'll need to add an initializer first so that our parentControllerclass can instantiate theLoggerclass. We'll callsuperat the end of the method, which will callinitializeon the parent class passing through the same parameters (which is the default whensuperis called with no parameters):controller_logger...