Install noisy animals:
bundle install
Then see the tests demonstrate how noisy the animals are:
bundle exec rspec
This small exercise is designed to help thinking about and improve code.
The NoisyAnimal class has some poor code in it. Can you spot and fix some problems?
When/If you're feeling comfortable with the code, try adding these animals:
- A snake that makes the noise "hiss" when it is loud and "slither" when it is not loud
- A mouse that is so silent that it outputs only one blank line, whether loud or quiet
Support the true
or false
values for the is_loud
flag in both cases.
Don't forget the tests for your new requirements! Don't change any existing tests.
- What problems can you identify if you think for 5 minutes before you start changing code?
- What sort of changes do you think will address these problems?
- Does your starting list of problems still feel complete?
- If you rewrote the list now, would it be different? How and why?
- Does your current assessment of the NoisyAnimal problems feel similar or different to other code you read or work with?
- Have you found yourself trying something and then realising it wouldn't work? How easy was it to get back to something that did work?
- Do you make git commits as you make your changes?
- How often do you run the tests? What if you could only run them once every 10 minutes? Or 30 minutes?
- What would it take to run the tests every time you changed a line of
noisy_animal.rb
? - Is it easier to add the new animals before or after addressing some of the problems?