Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a demonstration of testing with ShellSpec and is not intended to be merged. (Ref: #133)
getdeps
bpkg_utils
There is no need for the hard-to-understand test helper functions that are now required in bats.
lib/json
Directory structure
The
lib/json
is actually an external library. (It may be better to make it a submodule). ShellSpec uses a singlespec
directory for storing tests by default, but you can also place some/all more tests in individual directories.NOTE: This directory structure is a new feature in the latest ShellSpec, but during the creation of this demo, I found out that it has a bug when combined with dynamic parameterized tests. I will get right to work on fixing it. shellspec/shellspec#203
If you have kcov installed, you can use
shellspec --kcov
to measure the coverage. However, if you run it at the root of the project, you will not be able to measure the coverage oflib/json
. This is also probably a bug. The output of the coverage measurement is not supposed to be included in the repository, but it is included as a demonstration.Open
coverage/index.html
andlib/json/coverage/index.html
Arrange-Act-Assert pattern
I've combined several tests (assertions) into one. ShellSpec adopts 'each test should make only one evaluation' instead of 'each test should make only one expectation (assertion)'. Because in shell scripts, we often assert the side effects of a function, not its return value. Multiple evaluations in a single test are explicitly forbidden, and the evaluation cannot be placed after expectations. Therefore, the order Arrange-Act-Assert is always satisfied.