From d4b848b28bb1f8904f9be3e7d7802540eacad758 Mon Sep 17 00:00:00 2001 From: Dmytro Serdiuk Date: Sun, 17 Dec 2017 20:44:04 +0200 Subject: [PATCH] Apply template for tests names #98 --- CONTRIBUTING.md | 2 - src/main/git-elegant-clone | 2 +- src/test/git-elegant-add.bats | 2 +- src/test/git-elegant-check.bats | 46 +++++++++---------- src/test/git-elegant-clear-local.bats | 2 +- src/test/git-elegant-clone.bats | 6 +-- ...elegant.bats => git-elegant-commands.bats} | 12 +---- src/test/git-elegant-configure.bats | 10 ++-- src/test/git-elegant-feature.bats | 12 ++--- src/test/git-elegant-init.bats | 2 +- src/test/git-elegant-pull.bats | 4 +- src/test/git-elegant-push-after-rebase.bats | 2 +- src/test/git-elegant-push.bats | 2 +- src/test/git-elegant-rebase.bats | 2 +- 14 files changed, 48 insertions(+), 58 deletions(-) rename src/test/{git-elegant.bats => git-elegant-commands.bats} (68%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 089c7fb..7e19961 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,8 +37,6 @@ Test name template ------------------ Use the following test name template - `'': ` like `'check -s': trailing spaces in the staged changes`. -@todo #89 Apply test name template for all unit tests. Please update assertions if required. - Run --- Use one of the following commands to run the unit tests: diff --git a/src/main/git-elegant-clone b/src/main/git-elegant-clone index e5a9e3b..66767f6 100644 --- a/src/main/git-elegant-clone +++ b/src/main/git-elegant-clone @@ -2,7 +2,7 @@ set -e default() { - _validate "$1" "Clonable URL" + _validate "$1" "Cloneable URL" git clone "$1" cd $(basename -s .git $1) git elegant configure --local diff --git a/src/test/git-elegant-add.bats b/src/test/git-elegant-add.bats index 3eea4c3..95692fd 100644 --- a/src/test/git-elegant-add.bats +++ b/src/test/git-elegant-add.bats @@ -14,7 +14,7 @@ setup() { fake-pass git status } -@test "exit code is 0 when run 'git-elegant add'" { +@test "'add': successful adding of modified file" { run git-elegant add [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-check.bats b/src/test/git-elegant-check.bats index cb4f873..5a11e01 100644 --- a/src/test/git-elegant-check.bats +++ b/src/test/git-elegant-check.bats @@ -15,53 +15,53 @@ preconditions() { fake-pass git "elegant check --all" } -@test "exit code is 0 when run 'git-elegant check -a'" { +@test "'check': '-a' option is available" { preconditions run git-elegant check -a [ "$status" -eq 0 ] } -@test "'check -s': no trailing spaces in the staged changes" { - init-repo && add-st-change "no space" - check git-elegant check -s +@test "'check': '--all' option is available" { + preconditions + run git-elegant check --all [ "$status" -eq 0 ] - [ "${#lines[@]}" -eq 0 ] -} - -@test "'check -s': trailing spaces in the staged changes" { - init-repo && add-st-change "the space " - check git-elegant check -s - [ "$status" -eq 2 ] - [ "${lines[1]}" = "+the space " ] - } -@test "exit code is 0 when run 'git-elegant check -u'" { +@test "'check': '-u' option is available" { preconditions run git-elegant check -u [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant check --all'" { +@test "'check': '--unstaged' option is available" { preconditions - run git-elegant check --all + run git-elegant check --unstaged [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant check --staged'" { +@test "'check': '-s' option is available" { preconditions - run git-elegant check --staged + run git-elegant check -s [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant check --unstaged'" { +@test "'check': '--staged' option is available" { preconditions - run git-elegant check --unstaged + run git-elegant check --staged [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant check'" { - preconditions - run git-elegant check +@test "'check': no trailing spaces in the staged changes" { + init-repo && add-st-change "no space" + check git-elegant check -s [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] } + +@test "'check': trailing spaces in the staged changes" { + init-repo && add-st-change "the space " + check git-elegant check -s + [ "$status" -eq 2 ] + [ "${lines[1]}" = "+the space " ] + +} \ No newline at end of file diff --git a/src/test/git-elegant-clear-local.bats b/src/test/git-elegant-clear-local.bats index 9200bb3..fd35bdb 100644 --- a/src/test/git-elegant-clear-local.bats +++ b/src/test/git-elegant-clear-local.bats @@ -14,7 +14,7 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant clear-local'" { +@test "'clear-local': command is available" { run git-elegant clear-local [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-clone.bats b/src/test/git-elegant-clone.bats index d6f0f2e..4232de0 100644 --- a/src/test/git-elegant-clone.bats +++ b/src/test/git-elegant-clone.bats @@ -15,12 +15,12 @@ teardown() { clean-fake } -@test "print message when run 'git-elegant clone'" { +@test "'clone': raise an error if cloneable URL isn't set" { run git-elegant clone - [[ "${lines[0]}" =~ "Clonable URL is not set" ]] + [[ "${lines[0]}" =~ "Cloneable URL is not set" ]] } -@test "exit code is 0 when run 'git-elegant clone'" { +@test "'clone': clone the repo" { run git-elegant clone https://github.com/extsoft/elegant-git.git [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant.bats b/src/test/git-elegant-commands.bats similarity index 68% rename from src/test/git-elegant.bats rename to src/test/git-elegant-commands.bats index 8f8a7f6..dccf42b 100644 --- a/src/test/git-elegant.bats +++ b/src/test/git-elegant-commands.bats @@ -7,7 +7,7 @@ teardown() { clean-fake } -@test "print available commands when run 'git-elegant commands'" { +@test "'commands': print all available commands" { run git-elegant commands [ "${lines[0]}" = "feature" ] [ "${lines[1]}" = "pull" ] @@ -23,15 +23,7 @@ teardown() { [ ${#lines[@]} -eq 11 ] } - -@test "exit code is 10 when run 'git-elegant'" { - fake-pass git "elegant commands" - run git-elegant - [ "$status" -eq 10 ] -} - - -@test "exit code is 0 when run 'git-elegant commands'" { +@test "'commands': default exit code is 0" { run git-elegant commands [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-configure.bats b/src/test/git-elegant-configure.bats index 19f834a..d686f88 100644 --- a/src/test/git-elegant-configure.bats +++ b/src/test/git-elegant-configure.bats @@ -26,23 +26,23 @@ teardown() { clean-fake } -@test "'configure': exit code is 11 when run without arguments" { +@test "'configure': exit code is 11 when no arguments provided" { run git-elegant configure [ "$status" -eq 11 ] } -@test "'configure': exit code is 0 when run with '--global' argument" { +@test "'configure': '--global' option is available" { run git-elegant configure --global [ "$status" -eq 0 ] } -@test "'configure': exit code is 0 when run with '--local' argument" { +@test "'configure': '--local' option is available" { run git-elegant configure --local [ "$status" -eq 0 ] } -@test "'configure': sequence of the configuration is correct when run with '--global' argument" { +@test "'configure': sequence of the global git configuration is correct" { run git-elegant configure --global [ "${lines[0]}" = "commit message won't start with [|]: " ] [ "${lines[1]}" = "your user name [UserName]: " ] @@ -52,7 +52,7 @@ teardown() { [ ${#lines[@]} -eq 5 ] } -@test "'configure': sequence of the configuration is correct when run with '--local' argument" { +@test "'configure': sequence of the local git configuration is correct" { run git-elegant configure --local [ "${lines[0]}" = "commit message won't start with [|]: " ] [ "${lines[1]}" = "your user name [UserName]: " ] diff --git a/src/test/git-elegant-feature.bats b/src/test/git-elegant-feature.bats index 3cf10d6..dd342ab 100644 --- a/src/test/git-elegant-feature.bats +++ b/src/test/git-elegant-feature.bats @@ -13,22 +13,22 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant feature test-feature'" { +@test "'feature': branch with given name is created successfully" { run git-elegant feature test-feature [ "$status" -eq 0 ] } -@test "exit code is 255 when run 'git-elegant feature'" { +@test "'feature': exit code is 255 when branch name isn't set" { run git-elegant feature [ "$status" -eq 255 ] } -@test "print message when run 'git-elegant feature'" { +@test "'feature': print error message when branch name isn't set" { run git-elegant feature [[ "${lines[0]}" =~ "Feature name is not set" ]] } -@test "exit code is 0 when run 'git-elegant feature' with changes" { +@test "'feature': use stash for available changes" { fake-pass git "stash save elegant-git" "Saved working directory" fake-pass git "stash apply stash^{/elegant-git}" fake-pass git "stash drop stash@{0}" @@ -36,13 +36,13 @@ teardown() { [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant feature' without changes" { +@test "'feature': ignore stash if there are no changes" { fake-pass git "stash save elegant-git" "No local changes to save" run git-elegant feature test-feature [ "$status" -eq 0 ] } -@test "exit code is 100 when run 'git-elegant feature' with error at 'git stash drop'" { +@test "'feature': exit code is 100 when stash wasn't applied" { fake-pass git "stash save elegant-git" "Saved working directory" fake-pass git "stash apply stash^{/elegant-git}" fake-fail git "stash drop stash@{0}" diff --git a/src/test/git-elegant-init.bats b/src/test/git-elegant-init.bats index 99e55ff..20781e2 100644 --- a/src/test/git-elegant-init.bats +++ b/src/test/git-elegant-init.bats @@ -13,7 +13,7 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant init'" { +@test "'init': command is available" { run git-elegant init [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-pull.bats b/src/test/git-elegant-pull.bats index a5d6d36..bba386a 100644 --- a/src/test/git-elegant-pull.bats +++ b/src/test/git-elegant-pull.bats @@ -7,7 +7,7 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant pull' without parameters" { +@test "'pull': current local branch is pulled successfully" { fake-pass git "fetch --tags" fake-pass git pull @@ -15,7 +15,7 @@ teardown() { [ "$status" -eq 0 ] } -@test "exit code is 0 when run 'git-elegant pull' with parameter" { +@test "'pull': provided local branch is pulled successfully" { fake-pass git "checkout master" fake-pass git "fetch --tags" fake-pass git pull diff --git a/src/test/git-elegant-push-after-rebase.bats b/src/test/git-elegant-push-after-rebase.bats index 3728bf3..32e7cba 100644 --- a/src/test/git-elegant-push-after-rebase.bats +++ b/src/test/git-elegant-push-after-rebase.bats @@ -13,7 +13,7 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant push-after-rebase'" { +@test "'push-after-rebase': command is available" { run git-elegant push-after-rebase [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-push.bats b/src/test/git-elegant-push.bats index 7c73d01..b3c95ba 100644 --- a/src/test/git-elegant-push.bats +++ b/src/test/git-elegant-push.bats @@ -13,7 +13,7 @@ setup() { fake-pass git "push -u origin master:master" } -@test "exit code is 0 when run 'git-elegant push'" { +@test "'push': command is available" { run git-elegant push [ "$status" -eq 0 ] } diff --git a/src/test/git-elegant-rebase.bats b/src/test/git-elegant-rebase.bats index 8c8c278..8304fb6 100644 --- a/src/test/git-elegant-rebase.bats +++ b/src/test/git-elegant-rebase.bats @@ -12,7 +12,7 @@ teardown() { clean-fake } -@test "exit code is 0 when run 'git-elegant rebase'" { +@test "'rebase': command is available" { run git-elegant rebase [ "$status" -eq 0 ] }