# 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 editor ;
this example uses `python` with `pytest` and `nano`
```sh
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](https://git-gamble.is-cool.dev/slides_demo)
---
## First TDD loop <span aria-hidden="true">β°</span>
> Write a program that says `Hello world`
### First, <span aria-hidden="true">π΄</span> Red phase : write a test that fails for the good reason
<details name="first_loop_red" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496949.js" id="asciicast-496949" async></script>
</details>
<details name="first_loop_red">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello():
pass
def test_say_hello_world():
assert hello() == 'Hello world'
```
Then, gamble that the tests fail
```sh
git gamble --red
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
### Second, <span aria-hidden="true">π’</span> Green phase : write the minimum code to pass the tests
Let's fake it
<details name="first_loop_green_fail" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496951.js" id="asciicast-496951" async></script>
</details>
<details name="first_loop_green_fail">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello():
return 'Hello word'
```
Then, gamble that the tests pass
```sh
git gamble --green
```
Reverted {{#include ../../_logo_mini_back.html}}
</details>
Oh ! No !
I made a typo
```diff
def hello():
- return 'Hello word'
+ return 'Hello world'
```
Try again
Let's fake it **without typo**
<details name="first_loop_green_success" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496952.js" id="asciicast-496952" async></script>
</details>
<details name="first_loop_green_success">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello():
return 'Hello world'
```
Gamble again that the tests pass
```sh
git gamble --green
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
Yeah !
### Third, <span aria-hidden="true">π</span> Refactor phase : Nothing to refactor yet
---
Then <span aria-hidden="true">π</span> Repeat <span aria-hidden="true">β°</span>
## Second TDD loop <span aria-hidden="true">βΏ</span>
> Write a program that says `Hello` to the given name when a name is given
### <span aria-hidden="true">π΄</span> Red phase
<details name="second_loop_red" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496957.js" id="asciicast-496957" async></script>
</details>
<details name="second_loop_red">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def test_say_hello_name_given_a_name():
assert hello('Jon') == 'Hello Jon'
```
```sh
git gamble --red
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
### <span aria-hidden="true">π’</span> Green phase
Add a simple condition to handle both cases
<details name="second_loop_green" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496959.js" id="asciicast-496959" async></script>
</details>
<details name="second_loop_green">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello(arg=None):
if arg:
return f'Hello {arg}'
return 'Hello world'
```
```sh
git gamble --green
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
### <span aria-hidden="true">π</span> Refactor loop <span aria-hidden="true">β°</span>
#### <span aria-hidden="true">π</span> Refactor phase
It can be simplified
<details name="second_loop_refactor_1" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496961.js" id="asciicast-496961" async></script>
</details>
<details name="second_loop_refactor_1">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello(arg='world'):
return f'Hello {arg}'
```
```sh
git gamble --refactor
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
#### Still <span aria-hidden="true">π</span> Refactor phase : i have something else to refactor <span aria-hidden="true">βΏ</span>
Better naming
<details name="second_loop_refactor_2" open>
<summary>Asciinema</summary>
<script src="https://asciinema.org/a/496963.js" id="asciicast-496963" async></script>
</details>
<details name="second_loop_refactor_2">
<summary>Alternative text</summary>
```sh
nano test_hello.py
```
```python
def hello(name='world'):
return f'Hello {name}'
```
```sh
git gamble --refactor
```
Committed {{#include ../../_logo_mini_front.html}}
</details>
---
And so on... <span aria-hidden="true">βΏ</span>
<span aria-hidden="true">π</span> Repeat until you have tested all the rules, are satisfied and enough confident