I am not understanding how the TDD FIRST principle isn't being adhered to in the following code.
These are my notes about the FIRST principle:
- Fast: run (subset of) tests quickly (since you'll be running them all the time)
- Independent: no tests depend on others, so can run any subset in any order
- Repeatable: run N times, get same result (to help isolate bugs and enable automation)
- Self-checking: test can automatically detect if passed (no human checking of output)
- Timely: written about the same time as code under test (with TDD, written first!)
The quiz question:
Sally wants her website to have a special layout on the first Tuesday of every month. She has the following controller and test code:
# HomeController def index if Time.now.tuesday? render 'special_index' else render 'index' end end # HomeControllerSpec it "should render special template on Tuesdays" do get 'index' if Time.now.tuesday? response.should render_template('special_index') else response.should render_template('index') end end
What FIRST principle is not being followed?
- Fast
- Independent
- Repeatable
- Self-checking
- Timely
I'm not sure which FIRST principle is not being adhered to:
'special_index'
if it's Tuesday and 'index'
if it's not Tuesday.I chose Timely on the quiz because the test code was presented after the controller code. But I got the question wrong, and in retrospect, this wasn't a good choice. I'm not sure which FIRST principle isn't being followed here.
It's not Repeatable
as not everyday is Tuesday :) If you run this test on Monday you will get one result, if you run it on Tuesday, a different one.