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

Let Assertions Return Either #68

Closed
adius opened this issue Jan 13, 2018 · 4 comments · Fixed by #83
Closed

Let Assertions Return Either #68

adius opened this issue Jan 13, 2018 · 4 comments · Fixed by #83

Comments

@adius
Copy link

adius commented Jan 13, 2018

I think a structure like this would provide a much better separation of concerns:

shouldEqual :: String -> String -> Either String String
shouldEqual actual expected =
  if (actual /= expected)
  then Left "\"" <> actual <> "\" /= \"" <> expected <> "\""
  else Right ""


shouldBeOk :: forall r. Either String String -> Aff r Unit
shouldBeOk value = case value of
  Left error -> fail error
  Right _ -> (pure unit)


it "should do something" do
  shouldBeOk do
    actual <- getSomeEither
    expected <- getAnotherEither
    actual `shouldEqual` expected

Then all assertions would simply be of type String -> String -> Either String String

@adius
Copy link
Author

adius commented Jan 13, 2018

Now that I think of it, is the current signature necessary to run it async? 🤔

@safareli
Copy link
Member

safareli commented Jan 8, 2019

@adius would be great if you can take a look at #82 because there i'm adding:
hoistSpec :: (m ~> g) -> Spec' m ~> Spec' g

It means you can use something other then Aff Unit for it blocks, so if you have use Either String Unit, then you can do hoistSpec (either throw pure) which will throw for all Left values.

@safareli
Copy link
Member

safareli commented Jan 8, 2019

/cc @ad-si

This was referenced Jan 8, 2019
@owickstrom
Copy link
Collaborator

owickstrom commented Feb 2, 2019

@safareli correct me if I'm wrong, but this means that if one wants to run Either-based specs for only a subset of a test suite, they could hoistSpec that suite into a larger Aff Unit-based suite.

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

Successfully merging a pull request may close this issue.

3 participants