Skip to content

Commit

Permalink
Apply template for tests names
Browse files Browse the repository at this point in the history
  • Loading branch information
extsoft committed Dec 17, 2017
1 parent 341f738 commit d4b848b
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 58 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ Test name template
------------------
Use the following test name template - `'<command args>': <describe what will be tested>` 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:
Expand Down
2 changes: 1 addition & 1 deletion src/main/git-elegant-clone
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/git-elegant-add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
46 changes: 23 additions & 23 deletions src/test/git-elegant-check.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 " ]

}
2 changes: 1 addition & 1 deletion src/test/git-elegant-clear-local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
6 changes: 3 additions & 3 deletions src/test/git-elegant-clone.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
12 changes: 2 additions & 10 deletions src/test/git-elegant.bats → src/test/git-elegant-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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 ]
}
10 changes: 5 additions & 5 deletions src/test/git-elegant-configure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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]: " ]
Expand All @@ -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]: " ]
Expand Down
12 changes: 6 additions & 6 deletions src/test/git-elegant-feature.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ 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}"
run git-elegant feature test-feature
[ "$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}"
Expand Down
2 changes: 1 addition & 1 deletion src/test/git-elegant-init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
4 changes: 2 additions & 2 deletions src/test/git-elegant-pull.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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

run git-elegant pull
[ "$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
Expand Down
2 changes: 1 addition & 1 deletion src/test/git-elegant-push-after-rebase.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-push.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
2 changes: 1 addition & 1 deletion src/test/git-elegant-rebase.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}

1 comment on commit d4b848b

@0pdd
Copy link

@0pdd 0pdd commented on d4b848b Dec 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 89-d0540227 disappeared from CONTRIBUTING.md, that's why I closed #98. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.