-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from lindycoder/call_count-2
Support --once in mocking (Reapplying)
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
# Sample source code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
test_not_called_once() { | ||
mock some-command --once | ||
|
||
echo "Test stdout" | ||
echo "Test stderr" 1>&2 | ||
} | ||
|
||
test_called_twice() { | ||
mock some-command --once | ||
|
||
some-command | ||
assert ${?} succeeded | ||
some-command | ||
assert ${?} failed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,7 @@ test_that_fails_with_stderr() { | |
(bash fail-with-stderr.sh) | ||
assert ${?} succeeded | ||
} | ||
|
||
test_that_works() { | ||
: | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
|
||
test_specifying_once_fails_when_not_called() { | ||
cp -aR ${TEST_ROOT_DIR}/../test-fixtures/call_counts_tests/* . | ||
|
||
unset RUN_SINGLE_TEST | ||
actual=$(${TEST_ROOT_DIR}/../target/sbtest.sh call_counts.not_called_once) | ||
assert ${?} failed | ||
|
||
expected=$(cat <<-EXP | ||
Running Simple Bash Tests | ||
------------------------- | ||
call_counts.not_called_once...FAILED | ||
========================= | ||
FAIL: call_counts.not_called_once | ||
-------- STDOUT --------- | ||
Test stdout | ||
Command 'some-command' was expected to be called 1 time | ||
Called : 0 times | ||
-------- STDERR --------- | ||
Test stderr | ||
------------------------- | ||
------------------------- | ||
Ran 1 test | ||
>>> FAILURE (1 problem) <<< | ||
EXP | ||
) | ||
assert "${actual}" equals "${expected}" | ||
} | ||
|
||
test_specifying_once_fails_when_called_twice() { | ||
cp -aR ${TEST_ROOT_DIR}/../test-fixtures/call_counts_tests/* . | ||
|
||
unset RUN_SINGLE_TEST | ||
actual=$(${TEST_ROOT_DIR}/../target/sbtest.sh call_counts.called_twice) | ||
assert ${?} failed | ||
|
||
expected=$(cat <<-EXP | ||
Running Simple Bash Tests | ||
------------------------- | ||
call_counts.called_twice...FAILED | ||
========================= | ||
FAIL: call_counts.called_twice | ||
-------- STDOUT --------- | ||
Command 'some-command' was expected to be called 1 time | ||
Called : 2 times | ||
-------- STDERR --------- | ||
------------------------- | ||
------------------------- | ||
Ran 1 test | ||
>>> FAILURE (1 problem) <<< | ||
EXP | ||
) | ||
assert "${actual}" equals "${expected}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters