Hey there! We're thoughtbot, a design and development consultancy that brings your digital product ideas to life. We also love to share what we learn.
This coding exercise comes from Upcase, the online learning platform we run. It's part of the Fundamentals of TDD course and is just one small sample of all the great material available on Upcase, so be sure to visit and check out the rest.
Test code deserves the same care and effort as we put into writing our production code. In this exercise you'll take a messy test and refactor it to better capture the intent and tell a good story.
To start, you'll want to clone and run the setup script for the repo
git clone [email protected]:thoughtbot-upcase-exercises/tdd-spec-cleanup-exercise.git
cd tdd-spec-cleanup-exercise
bin/setup
Your goal is to refactor the provided spec to help it tell a good story. Currently the spec makes heavy use of features like let
and before
, obscuring the behavior and assertions in each of the specs. Instead, we want each spec to stand on its own, telling a small clear story about the behavior of our model
- Edit the spec in
spec/models/invitation_spec.rb
. - Refactor the spec, cleaning up and clarifying things without changing the test or model behavior
- As with any good refactoring, your tests should remain green throughout. Be sure to check with:
$ bin/rspec spec/models/invitation_spec.rb
Your goal is to refactor the specs in that file to clarify the behavior and tell a good story
- Keep the 4 phase test model in mind (likely you'll only need 3 as tear down is automated)
- Feel free to extract helper methods to abstract away details while keeping setup explicit to the spec
Revisit the video on Telling a Story with Your Tests for tips on how to tackle this cleanup.
If you find yourself stuck, be sure to check out the associated Upcase Forum discussion for this exercise to see what other folks have said.
When you've finished the exercise, head on back to the Fundamentals of TDD course to find the next exercise, or explore any of the other great content on Upcase.
tdd-spec-cleanup-exercise is Copyright © 2015-2018 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
This exercise is maintained and funded by thoughtbot, inc.
The names and logos for Upcase and thoughtbot are registered trademarks of thoughtbot, inc.