Demo

git-gamble's demo to develop using TCRDD by doing baby steps

on a simple program

git-gamble works with all languages and tools and editors

for this example, i use python with pytest and nano

export GAMBLE_TEST_COMMAND='pytest --quiet'

note : for a simpler demo, test code and production code are in the same file

Alternatively : you can also watch the slides about the demo


First TDD loop ➰

Write a program that says Hello world

First, πŸ”΄ Red phase : write a test that fails for the good reason

Alternative text
nano test_hello.py
def hello():
    pass

def test_say_hello_world():
    assert hello() == 'Hello world'

Then, gamble that the tests fail

git gamble --red

βœ”οΈ Committed

Second, 🟒 Green phase : write the minimum code to pass the tests

Let's fake it

Alternative text
nano test_hello.py
def hello():
    return 'Hello word'

Then, gamble that the tests pass

git gamble --green

❌ Reverted

Oh no !

I made a typo

 def hello():
-    return 'Hello word'
+    return 'Hello world'

Try again

Let's fake it without typo

Alternative text
nano test_hello.py
def hello():
    return 'Hello world'

Gamble again that the tests pass

git gamble --green

βœ”οΈ Committed

Yeah !

Third, πŸ”€ Refactor phase : Nothing to refactor yet


Then πŸ” Repeat ➰

Second TDD loop ➿

Write a program that says Hello to the given name when a name is given

πŸ”΄ Red phase

Alternative text
nano test_hello.py
def test_say_hello_name_given_a_name():
    assert hello('Jon') == 'Hello Jon'
git gamble --red

βœ”οΈ Committed

🟒 Green phase

Add a simple condition to handle both cases

Alternative text
nano test_hello.py
def hello(arg=None):
    if arg:
        return f'Hello {arg}'
    return 'Hello world'
git gamble --green

βœ”οΈ Committed

πŸ”€ Refactor loop ➰

πŸ”€ Refactor phase

It can be simplified

Alternative text
nano test_hello.py
def hello(arg='world'):
    return f'Hello {arg}'
git gamble --refactor

βœ”οΈ Committed

Still πŸ”€ Refactor phase : i have something else to refactor ➿

Better naming

Alternative text
nano test_hello.py
def hello(name='world'):
    return f'Hello {name}'
git gamble --refactor

βœ”οΈ Committed


And so on... ➿

πŸ” Repeat until you have tested all the rules, are satisfied and enougth confident