lib/ndjson_formatter.rb in rspec-ndjson-formatter-1.0.0 vs lib/ndjson_formatter.rb in rspec-ndjson-formatter-1.1.0
- old
+ new
@@ -1,10 +1,16 @@
require "ndjson_formatter/version"
require "json"
class NdjsonFormatter
- RSpec::Core::Formatters.register self, :stop, :example_started, :example_group_started
+ RSpec::Core::Formatters.register self,
+ :stop,
+ :example_started,
+ :example_passed,
+ :example_failed,
+ :example_pending,
+ :example_group_started
def initialize(io)
@io = io
@testables = {}
end
@@ -32,10 +38,27 @@
line: ex.metadata[:line_number],
parent_id: example_parent_id(ex),
})
end
+ def example_passed(example_notification)
+ update_testable(example_notification.example, status: "passed")
+ end
+
+ def example_failed(failed_example_notification)
+ update_testable(failed_example_notification.example,
+ status: "failed",
+ message: failed_example_notification.message_lines,
+ backtrace: failed_example_notification.formatted_backtrace)
+ end
+
+ def example_pending(example_notification)
+ update_testable(example_notification.example,
+ status: "pending",
+ message: Array(example_notification.example.execution_result.pending_message))
+ end
+
def stop(_arg)
dump
end
private
@@ -60,9 +83,13 @@
@top_level = parentless_testable
else
@testables[parent_id][:children] << parentless_testable
end
@testables[parentless_testable[:id]] = parentless_testable
+ end
+
+ def update_testable(testable, attributes)
+ @testables[testable.id].merge!(attributes)
end
def format_id(metadata)
return unless metadata
"#{metadata.fetch(:file_path)}[#{metadata.fetch(:scoped_id)}]"