-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
If I run
load 'test_helper/bats-mock/stub'
# this is the "code under test"
# it would normally be in another file
format_date() {
date -r 222
#foo bar
}
setup() {
_DATE_ARGS='-r 222'
stub date \
"${_DATE_ARGS} : echo 'I am stubbed!'" \
"${_DATE_ARGS} : echo 'Wed Dec 31 18:03:42 CST 1969'"
#_FOO_ARGS='bar'
#stub foo \
# "${_FOO_ARGS} : echo "FOOBAR""
}
teardown() {
unstub date
#unstub foo
}
@test "date format util formats date with expected arguments" {
run format_date
[ "${lines[0]}" = "I am stubbed!" ]
#[ "${lines[1]}" = "FOOBAR" ]
# result="$(format_date)"
# [ "$result" == 'Wed Dec 31 18:03:42 CST 1969' ]
}
It will fail because the plan for date is met due to date only being called once.
However if I run
load 'test_helper/bats-mock/stub'
# this is the "code under test"
# it would normally be in another file
format_date() {
date -r 222
foo bar
}
setup() {
_DATE_ARGS='-r 222'
stub date \
"${_DATE_ARGS} : echo 'I am stubbed!'" \
"${_DATE_ARGS} : echo 'Wed Dec 31 18:03:42 CST 1969'"
_FOO_ARGS='bar'
stub foo \
"${_FOO_ARGS} : echo "FOOBAR""
}
teardown() {
unstub date
unstub foo
}
@test "date format util formats date with expected arguments" {
run format_date
[ "${lines[0]}" = "I am stubbed!" ]
[ "${lines[1]}" = "FOOBAR" ]
# result="$(format_date)"
# [ "$result" == 'Wed Dec 31 18:03:42 CST 1969' ]
}
Then it will succeed even though the plan for date still isn't met.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels