Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce Expect.true/false with a better API? #224

Open
Janiczek opened this issue Sep 6, 2023 · 1 comment
Open

Reintroduce Expect.true/false with a better API? #224

Janiczek opened this issue Sep 6, 2023 · 1 comment

Comments

@Janiczek
Copy link
Collaborator

Janiczek commented Sep 6, 2023

Maybe we should make it easier to do this:

|> Expect.equal True
|> Expect.onFail "The URL should still be present in the final URL after running autolinksUrl"

by having something like

|> Expect.true { onFalse = "The URL ..." }

The previous maintainers' reasons for removing Expect.true was that it took away the spotlight from better solutions (Expect.equalLists, ...), but sometimes you just have to work with predicates. It's not always possible/practical to use the other helpers. Let's trust our users to understand when to use which solution?

@gampleman
Copy link
Contributor

gampleman commented Sep 6, 2023

💯

Spitballing some ideas:

Expect.predicate : (a -> Bool) -> (a -> String) -> a -> Expectation

One issue I found making custom predicate based assertions is that to make the error message good you need to have a way of including whatever you computed into the error message, but given that you usually do this in pipelines, this becomes annoying.

\someFuzz ->
   someFuzz 
      |> SystemUnderTest.performOperation
      |> TestUtils.assertProperty
      |> Expect.equal True

to add nicer error message:

\someFuzz ->
   let 
      resultingValue =
           someFuzz 
               |> SystemUnderTest.performOperation
   in
   resultingValue
      |> TestUtils.assertProperty
      |> Expect.equal True
      |> Expect.onFail ("assertProperty failed because " ++ Debug.toString resultingValue ++ " had this specific issue")

Perhaps this API could even be improved to:

Expect.predicate : (a -> Bool) -> (String -> String) -> a -> Expectation

Where elm-test calls Debug.toString for you, so that its easier to package up custom assertions into elm packages?

\someFuzz ->
   someFuzz 
      |> SystemUnderTest.performOperation
      |> Expect.predicate TestUtils.assertProperty 
           (\repr -> 
              "assertProperty failed because " ++ rear ++ " had this specific issue"
           )

Viir added a commit to Viir/elm-bigint that referenced this issue Nov 11, 2023
Running the latest version of elm-test-rs on this project failed with the following error message:

```
Error: Failed to solve dependencies for tests to run

Caused by:
    This version of elm-test-rs only supports elm-explorations/test 2.0.0 <= v < 3.0.0, but you have 1.1.0 <= v < 2.0.0 in your dependencies
```

The commit updates the dependencies to enable running tests with the latest version of elm-test-rs
Changes in the API of the test framework required adaption of the test code. For details on changes in the test framework, see:

+ elm-explorations/test@e3584bd (elm-explorations/test#46, elm-explorations/test#224)
+ elm-explorations/test@9aa32d9 (elm-explorations/test#48)
+ elm-explorations/test@387aa2d (elm-explorations/test#157)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants