Testing culture: RGR cycle
This course teaches the Red-Green-Refactor discipline using one service and one spec from this app: Identity::AccountUpdateService and its RSpec file. It follows commit 999182a, which fixed a bug where a rejected password change could still commit a name change. The lessons trace the regression test as Red against the old code, then as Green against the fix. They also explain why a test that never failed proves nothing, how to refactor only under a green suite, and why the cycle repeats as a loop.
What you'll learn
- ✓The three states of Red-Green-Refactor and their fixed order
- ✓Why a test that never failed proves nothing about the bug it guards against
- ✓Making the smallest change that turns a red test green
- ✓How a transaction rolls back on a raised exception but commits on a false return
- ✓Refactoring only while the suite is green, without changing behavior
- ✓Reading negative and positive examples as one complete cycle
Red-green-refactor: the discipline, and the spec behind this course
That's the spec file this course follows, run for this course. Gemfile line 60 says gem "rspec-rails": this app is tested with RSpec, not Minitest. The discipline this course teaches works the same in either framework, and every example comes from this app's own code.
Read the full lesson free →Curriculum
7 lessonsRed-green-refactor: the discipline, and the spec behind this course
Introduces the three states of Red-Green-Refactor and the service and spec file followed through every lesson.
Red: a test that never failed never proved anything
Traces the pre-fix code and shows why the regression test fails against it, which is the Red step.
Green: the smallest change that makes it pass
Walks through the commit's fix, which switches to bang writes, and shows the same test passing as Green.
Why green only means something because red happened first
Explains why a test that only ran against correct code proves nothing, using a flawed test as example.
Refactor: only under a green suite
Covers refactoring only under a green suite, with a small reshaping of update_password! that keeps behavior intact.
The whole cycle, in one context of this app's spec
Reads the spec's together-context as one cycle: two negative cases for the bug and one positive case.
Putting it together: RGR as a loop, not a checklist
Reviews the whole cycle and treats Red-Green-Refactor as a loop that repeats for each new behavior.