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

ShellSpec tests #134

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

ShellSpec tests #134

wants to merge 5 commits into from

Conversation

ko1nksm
Copy link
Member

@ko1nksm ko1nksm commented Mar 28, 2021

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 single spec 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 of lib/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 and lib/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant