Skip to content

Instantly share code, notes, and snippets.

@igrep
Created July 13, 2018 07:40
Show Gist options
  • Save igrep/6d1d0f1c3d9e8e4aff3746d0a51aedb8 to your computer and use it in GitHub Desktop.
Save igrep/6d1d0f1c3d9e8e4aff3746d0a51aedb8 to your computer and use it in GitHub Desktop.
Usage plan of Givens Testing Library: More RSpec-like testing library in Haskell.
describe "example group" $ do
-- Equivalent with RSpec's `let!(:hoge){ 1 }`.
-- An action passed to `given` function is executed every time
-- an example (defined by `it`) in the `describe` block is executed,
-- then the action's result is cached until the example's execution completes.
hoge <- given $ return 1
-- Equivalent with RSpec's `let(:hoge){ 1 }` (without exclamation).
hogeIfNecessary <- givenIfNecessary $ runOnlyIfReferred
-- To get the value of `given`, use `refer`.
foo <- given ((+ 1) <$> refer hoge)
-- Same as RSpec's `before(:each)`
before $
putStrLn =<< refer foo
it "an example" $ do
refer hoge `shouldReturn` 1
it "another example" $ do
refer foo `shouldReturn` 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment