Skip to content

Instantly share code, notes, and snippets.

@piperniehaus
Created May 6, 2018 22:47
Show Gist options
  • Save piperniehaus/63bbc89d560a3a0b91004615088fcf3d to your computer and use it in GitHub Desktop.
Save piperniehaus/63bbc89d560a3a0b91004615088fcf3d to your computer and use it in GitHub Desktop.

A simple example

Write a test that expects a function to exist.

    describe "combineStrings"
        [ test "combines some strings" <|
            \_ ->
                combineStrings "a" "b"
                    |> Expect.equal "ab"
        ]

The compiler fails.

  Cannot find variable `combineStrings`

  12|                 combineStrings "a" "b"
                      ^^^^^^^^^^^^^^

Make the function exist in the simplest possible way.

  combineStrings : String -> String -> String
  combineStrings string1 string2 =
    ""

The code compiles, but the tests fail.

  ↓ combineStrings
  ✗ combines some strings

      ""
      ╷
      │ Expect.equal
      ╵
      "ab"



  TEST RUN FAILED

Write code that makes the tests pass.

  combineStrings : String -> String -> String
  combineStrings string1 string2 =
    string1 ++ string2

BOOM! And now, refactor.

  TEST RUN PASSED

  Duration: 83 ms
  Passed:   1
  Failed:   0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment