Skip to content

Add shellspec and bats tests #94

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ the command.
The files should be placed in .git/hooks
In the directory hooks you can find examples of all the hooks available.

## Testing

Unit level tests are written with [Bats](https://github.com/bats-core/bats-core) and behavioural tests are written with [ShellSpec](https://github.com/shellspec/shellspec). Both tools must be installed locally and available on your `PATH`.

Run all tests with:

```shell
bats test/bats
shellspec
```


## Showing your appreciation

Expand Down
17 changes: 17 additions & 0 deletions spec/git_flow_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Describe 'git-flow'
Describe 'version command'
It 'prints current version'
When run script ../git-flow version
The output should eq '2.2.1 (CJS Edition)'
The status should be success
End
End

Describe 'usage without arguments'
It 'shows help text'
When run script ../git-flow
The status should be failure
The output should start with 'usage: git flow'
End
End
End
32 changes: 32 additions & 0 deletions test/bats/gitflow_common.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats

setup() {
# Source required scripts
source "$BATS_TEST_DIRNAME/../../gitflow-shFlags" >/dev/null
source "$BATS_TEST_DIRNAME/../../gitflow-common"
}

@test "check_boolean returns true for yes" {
run bash -c 'check_boolean yes'
[ "$status" -eq 0 ]
}

@test "check_boolean returns false for no" {
run bash -c 'check_boolean no'
[ "$status" -eq 1 ]
}

@test "check_boolean returns error for maybe" {
run bash -c 'check_boolean maybe'
[ "$status" -eq 2 ]
}

@test "startswith detects prefix" {
run bash -c 'startswith foobar foo'
[ "$status" -eq 0 ]
}

@test "startswith detects absence of prefix" {
run bash -c 'startswith foobar bar'
[ "$status" -ne 0 ]
}