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
Controller
class does indeed have access to the instantiatedLogger
class defined in theLoggerController
initializer: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
ControllerLogger
module. We'll need to add an initializer first so that our parentController
class can instantiate theLogger
class. We'll callsuper
at the end of the method, which will callinitialize
on the parent class passing through the same parameters (which is the default whensuper
is called with no parameters):controller_logger...