Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Add a minimalist formatter (c/quickfix style output) #2614

Merged
merged 3 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/rspec/core/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module RSpec::Core::Formatters
autoload :JsonFormatter, 'rspec/core/formatters/json_formatter'
autoload :BisectDRbFormatter, 'rspec/core/formatters/bisect_drb_formatter'
autoload :ExceptionPresenter, 'rspec/core/formatters/exception_presenter'
autoload :MinimalFormatter, 'rspec/core/formatters/minimal_formatter'

# Register the formatter class
# @param formatter_class [Class] formatter class to register
Expand Down Expand Up @@ -212,6 +213,8 @@ def built_in_formatter(key)
JsonFormatter
when 'bisect-drb'
BisectDRbFormatter
when 'm', 'minimal'
MinimalFormatter
end
end

Expand Down
23 changes: 23 additions & 0 deletions lib/rspec/core/formatters/minimal_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RSpec::Support.require_rspec_core "formatters/base_formatter"

module RSpec
module Core
module Formatters
# @private
class MinimalFormatter < BaseFormatter
Copy link
Member

@myronmarston myronmarston May 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Minimal" is a subjective term -- I can imagine many different minimal formatters that output different things. Here it seems like this formatter is focused on printing a list of failures. WDYT about calling this FailureListFormatter? Seems like a more accurate name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, naming things is hard

The formatter was initially called CFormatter — which was probably an even poorer choice — because it's output look like what a compiler produce…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to change the name, FailureListFormatter seems appropriate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2624

Formatters.register self, :example_failed, :dump_profile, :message

def example_failed(failure)
output.puts "#{failure.example.location}:#{failure.example.description}"
end

# Discard profile and messages
#
# These outputs are not really relevant in the context of this minimal
# formatter.
def dump_profile(_profile); end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so if you want to silence output, can we get a comment here explaining that? Also what about the other output? start / end etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially chose to discard the profile output because it produce a big chunk of information which is not really useful in the context of an editor (and since the formatter was renamed "minimal" it may make even more sense to discard any "extra" output), but I do not have strong opinion about this, and if you prefer to keep these messages I can amend my work accordingly.

I found out that message can be defined to discard more informational messages, and added a commit to include this with the requested comment. Please review and comment / resolve this conversation.

Thanks!

def message(_message); end
end
end
end
end
1 change: 1 addition & 0 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def parser(options)
' [d]ocumentation (group and example names)',
' [h]tml',
' [j]son',
' [m]inimal (suitable for editors integration)',
' custom formatter class name') do |o|
options[:formatters] ||= []
options[:formatters] << [o]
Expand Down
19 changes: 19 additions & 0 deletions spec/rspec/core/formatters/minimal_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rspec/core/formatters/minimal_formatter'

module RSpec::Core::Formatters
RSpec.describe MinimalFormatter do
include FormatterSupport

it 'produces the expected full output' do
output = run_example_specs_with_formatter('minimal')
expect(output).to eq(<<-EOS.gsub(/^\s+\|/, ''))
|./spec/rspec/core/resources/formatter_specs.rb:4:is marked as pending but passes
|./spec/rspec/core/resources/formatter_specs.rb:36:fails
|./spec/rspec/core/resources/formatter_specs.rb:40:fails twice
|./spec/rspec/core/resources/formatter_specs.rb:47:fails with a backtrace that has no file
|./spec/rspec/core/resources/formatter_specs.rb:53:fails with a backtrace containing an erb file
|./spec/rspec/core/resources/formatter_specs.rb:71:raises
EOS
end
end
end