-
Notifications
You must be signed in to change notification settings - Fork 514
Need more information in pretty output #192
Description
If a test fails, the output looks like this:
foo.bash:
foo () {
echo baz
}
foo_spec.bash:
source ./foo.bash
@test "foo equals bar" {
expected_result="bar"
run foo
[ "$status" -eq 0 ]
[ "$output" = "$expected_output" ]
}
[user@host ~]% bats foo_spec.bats
✗ foo equals bar
(in test file foo_spec.bats, line 6)
`[ "$output" = "$expected_output" ]' failed
2 tests, 1 failure, 1 skipped
bats lets me know which particular assertion failed, but it gives me no useful information about what the expected result was or what the actual result was. This makes it challenging and time-consuming to debug the function or script under test. In order to figure out that bats expected foo to output bar but received baz instead, I have to add printf/echo-style debugging statements to my script and/or my bats spec.
Compare this to, for instance, rspec:
foo.rb:
def foo()
"baz"
end
foo_spec.rb:
require_relative 'foo'
describe 'foo' do
it 'should return "bar"' do
actual_result = foo
expected_result = 'bar'
expect(actual_result).to eq(expected_result)
end
end
[user@host ~]% rspec foo_spec.rb
F
Failures:
1) foo should return "bar"
Failure/Error: expect(actual_result).to eq(expected_result)
expected: "bar"
got: "baz"
(compared using ==)
# ./foo_spec.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.01638 seconds (files took 0.12804 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./foo_spec.rb:4 # foo should return "bar"
The rspec output clearly prints the expected value and the received value, making it easy to debug the failing function being tested. I can quickly and easily see that there is a typo in the return statement of the foo method.