1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-26 06:38:40 +03:00
applied-fp-course/level04
Sean Chalmers 59a516d481 Updated DB for more clarity about withTable.
Added doctests and a shout out to what is going on with "$$tablename$$" in the
``withTable`` function.

Updated the level04 tests file to be a bit more defined and provide an example
of a test that Hspec.Wai lets you write. Information was very thin on the ground
in that file so it would have been too difficult without assistance.

Provided a bit more information about cool things that ``ghcid`` can do that I
didn't know about. :D

Fixes #9, #7, #5
2017-10-05 09:18:18 +10:00
..
bin Fix project restructure 2017-08-14 16:48:34 +10:00
src/FirstApp Removes a function that was just constructors 2017-09-12 15:42:07 +10:00
tests Updated DB for more clarity about withTable. 2017-10-05 09:18:18 +10:00
appconfig.json Add guidance about handling requests without persistent storage. 2017-09-11 10:29:56 +10:00
changelog.md change changelog files to lowercase 2017-09-01 11:17:26 +10:00
default.nix Overhauled nix file setup to be more like the other QFPL projects. 2017-09-18 10:14:29 +10:00
level04.cabal Merge branch 'master' of gitlab.com:qfpl/applied-fp-course 2017-09-12 13:41:26 +10:00
level04.nix Overhauled nix file setup to be more like the other QFPL projects. 2017-09-18 10:14:29 +10:00
LICENCE update copyright notice 2017-09-12 11:51:26 +10:00
README.md Updated DB for more clarity about withTable. 2017-10-05 09:18:18 +10:00
Setup.hs Add Level 04 2017-08-11 10:40:05 +10:00
test.json Rebuilt Conf File Read Handling 2017-09-12 11:21:27 +10:00

Level 04

In this exercise we're going to add some tests to our application. Because types are awesome, and tests are pretty good. But types AND tests is pretty much perfect.

These tests will not be awe inspiring, this exercise is primarily to introduce you to adding tests to your Haskell application. The setup of the Cabal file is already completed for you, but will be covered.

As is to be expected, there are multiple testing frameworks and packages available but we will only cover one here. We will use the HSpec framework, with the hspec-wai package to make our lives a bit easier.

Start in tests/Test.hs.

Aside: Tool Introduction - ghcid

Additionally we'd like to introduce a command line tool that you may find useful for Haskell development; ghcid. This is a very lightweight tool that works for any project with a functioning cabal setup.

If you would like to use it, consult its documentation for how to install it, and then in an spare open terminal window, navigate to the root of the Haskell project and run $ ghcid.

It will then attempt to build your project, if errors are found they will be displayed. But more importantly you can go back to editing files in the project and ghcid will refresh in the background. Providing you with new error messages or All Good if it cannot find any errors.

ghcid provides extremely fast feedback, allowing for a nice development process with constant feedback about your changes. It is very useful in tandem with type holes. Give it a try!

ghcid can also help out when you're writing your tests. Since normally the source and other packages that are listed in a test-suite configuration section in the Cabal file are not loaded. You can manually tell ghcid to load and examine these files with the following command:

$ ghcid -c "cabal repl level0N-tests"'