exercism:main
← johnsyweb:paj/add-test-case-for-nil-in-resistor-color
opened 09:02AM - 26 Oct 23 UTC
#### Context
When completing https://exercism.org/tracks/crystal/exercises/re…sistor-color , the signature for `def self.color_code(color : String) : Int32 | Nil` shows that the method can return `nil` but there's no spec to describe _why_.
#### Change
- Add test for nil return case
- Improve output for `crystal spec -v`
#### Considerations
0f100515 is not required but I think it improves the output.
<details>
<summary>Before: `crystal spec -v `</summary>
```
ResistorColor
Black
White
Orange
handles input that is not a recognised color
Colors
Pending:
ResistorColor White
ResistorColor Orange
ResistorColor handles input that is not a recognised color
ResistorColor Colors
Failures:
1) ResistorColor Black
Failure/Error: ResistorColor.color_code("black").should eq(0)
Expected: 0
got: nil
# spec/resistor_color_spec.cr:6
Finished in 331 microseconds
5 examples, 1 failures, 0 errors, 4 pending
Failed examples:
crystal spec spec/resistor_color_spec.cr:5 # ResistorColor Black
```
</details>
<details>
<summary>After `crystal spec -v`</summary>
```
ResistorColor
.color_code
finds the value for black
finds the value for white
finds the value for orange
handles input that is not a recognised color
.colors
returns an array of known colors
Pending:
ResistorColor .color_code finds the value for white
ResistorColor .color_code finds the value for orange
ResistorColor .color_code handles input that is not a recognised color
ResistorColor .colors returns an array of known colors
Failures:
1) ResistorColor .color_code finds the value for black
Failure/Error: ResistorColor.color_code("black").should eq(0)
Expected: 0
got: nil
# spec/resistor_color_spec.cr:7
Finished in 299 microseconds
5 examples, 1 failures, 0 errors, 4 pending
Failed examples:
crystal spec spec/resistor_color_spec.cr:6 # ResistorColor .color_code finds the value for black
```
</details>