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

A few more expectations #35

Open
declension opened this issue May 15, 2020 · 3 comments
Open

A few more expectations #35

declension opened this issue May 15, 2020 · 3 comments

Comments

@declension
Copy link

First of all - thanks for Hspec, it's great! Really useful both in and out of work.

I've got a few small helper expectations (e.g. shouldExceed, shouldInclude, shouldExist) that increasingly I / we're using to help with descriptive failures (and extra readable tests especially for beginners).

Is this codebase taking PRs, or would you prefer these be published elsewhere / kept private?

@sol
Copy link
Member

sol commented Nov 1, 2020

@declension Sorry for the late reply!

I'm somewhat conservative with adding stuff to Test.Hspec.Expectations, however, we can add stuff to Test.Hspec.Expectations.Contrib and move them to Test.Hspec.Expectations if they proof useful.

If you want to create a separate package, say hspec-extras or something, then that's fine too, of course.

BTW, I would like to see the type signatures of shouldExceed, shouldInclude, shouldExist, if possible.

@declension
Copy link
Author

declension commented Nov 5, 2020

Great, thanks @sol and no worries!

I'm more than happy with the Contrib proposal. I'm not a Haskell expert, so am happy to take suggestions here.

Anyway I've dug out some of that code and will try to tidy a bit. Here are some ideas

shouldExceed :: (HasCallStack, Show a, Ord a) => a -> a -> Expectation
shouldExceed = shouldBeGreaterThan

shouldBeGreaterThan :: (HasCallStack, Show a, Ord a) => a -> a -> Expectation
shouldBeLessThan :: (HasCallStack, Show a, Ord a) => a -> a -> Expectation

Updated version of showInclude to be less monomorphic to Lists... but not sure what to think about Show (t a) but it's nice to have the actual container shown (as with the list expectations)...

shouldInclude :: (HasCallStack, Show a, Eq a, Foldable t, Show (t a)) 
              => t a
              -> a 
              -> Expectation

Debatable if this one is useful, but can produce nicer error messages, and sometimes you don't want to specify the Just foo result

shouldExist :: (HasCallStack, Show a) => String -> Maybe a -> Expectation

@declension
Copy link
Author

@sol should I push a PR to see some code?

declension pushed a commit to declension/hspec-expectations that referenced this issue Apr 28, 2021
 * Add a new `shouldInclude` (hspec#38 / hspec#35)
 * Also, a more general `shouldIncludeAll` which tests provides subset-like expectations (generalised to any `Foldable`s), with helpful (hopefully) messaging about missing elements
 * Replicate a few unexported helper functions, rather than mess with the overall structure
 * Add some tests around these
 * Update Hpack / Cabal

Closes hspec#38
declension added a commit to declension/hspec-expectations that referenced this issue Apr 28, 2021
 * Add a new `shouldInclude` (hspec#38 / hspec#35)
 * Also, a more general `shouldIncludeAll` which tests provides subset-like expectations (generalised to any `Foldable`s), with helpful (hopefully) messaging about missing elements
 * Replicate a few unexported helper functions, rather than mess with the overall structure
 * Add some tests around these
 * Update Hpack / Cabal

Closes hspec#38
declension added a commit to declension/hspec-expectations that referenced this issue Apr 28, 2021
 * Add a new `shouldInclude` (hspec#38 / hspec#35)
 * Also, a more general `shouldIncludeAll` which provides subset-like expectations (generalised to any `Foldable`s), with helpful (hopefully) messaging about missing elements
 * Add some tests around these
 * Replicate a few unexported helper functions, rather than mess with the overall structure
 * Update Hpack / Cabal

Closes hspec#38
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