Skill Level: Beginner - Intermediate
Time Limit: 45 minutes
This is a challenge for learning Rubocop and how to do things the 'ruby' way. You will also learn about refactoring and why it's important.
You have been tasked to clean up Gem City. Luckily, your boss has paired you up with the newest advancement in code enforcement technology, Rubocop.
- Install the required gems
gem install bundler
bundle install
- Run rspec with
rspec gem_city_spec.rb
and then get a feel for the code that's passing. - Run rubocop with
rubocop
orrubocop <filename>
and see what's failing. - Correct all rubocop errors.
- Rerun the tests and rubocop. If there are no complaints, congratulations you've successfully cleaned up the streets of Gem City. There are 3 lines in the rspec file that you can change, leave the rest.
Bonus: Write the city demographics feature
- Uncomment the block of code at the end of the spec file
- Write the code to make the test pass.
- Run rubocop and then make the corrections.
- Rerun your test. If it passes, you've successfully refactored your function.
Advanced Challenge: See how short you can make the GemCity class while still passing Rubocop and rspec tests
- Why would you want to follow standards?
- What is the purpose of refactoring, if it works, why refactor?
- How can refactoring help us expand our code?
- The bonus challenge follows a process called Red, Green, Refactor.