Missing failure details when using HTML formatter with "aggregate_failures"
Created by: samuel-hcl
require 'rspec'
RSpec.configure do |rspec_config|
rspec_config.color = true
rspec_config.tty = true
rspec_config.add_formatter 'html', 'log.html'
rspec_config.add_formatter 'documentation'
rspec_config.around { |example| aggregate_failures { example.run } }
end
RSpec.describe 'html formatter with aggregate failures' do
it 'has two failures' do
response_code = 400
response_body = { message: 'error' }
expect(response_code).to eq 200
expect(response_body[:message]).to eq 'success'
end
it 'has one failure' do
response_code = 200
response_body = { message: 'success' }
expect(response_code).to eq 200
expect(response_body[:message]).to eq 'ok'
end
it 'has one failure and one error' do
response_code = 200
response_body = { message: 'success' }
list = { name: 'test'}
expect(response_code).to eq 200
expect(response_code).to eq 202
expect(list[:list][0][:name]).to eq 2
expect(response_body[:message]).to eq 'ok'
end
end
Running the above code with RSpec 3.5.2 generates a html log file with poor failure details for the test case with two failures. It just give me the stack trace (in the wrong place, not in the example) and this:
has two failures 0.01796s
./rspectest.rb:10:in `block (2 levels) in <top (required)>'
The test case with one failure is fine:
has one failure 0.00049s
Failure/Error: expect(response_body[:message]).to eq 'ok'
expected: "ok"
got: "success"
(compared using ==)
./rspectest.rb:26:in `block (2 levels) in <top (required)>'
./rspectest.rb:10:in `block (3 levels) in <top (required)>'
./rspectest.rb:10:in `block (2 levels) in <top (required)>'
It would be good if the html output for the test with two failures was like the output of the documentation formatter.
EDIT: added another example with poor failure report: when there is a failure (an expectation that is not met) and an error (like NoMethodError) in the same example.