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

Commit 777d85f

Browse files
smortexJonRowe
authored andcommitted
Add a minimalist formatter (c/quickfix style output) (#2614)
* Add a minimalisr formatter This formatter outputs failures in a similar fashion to the C compiler — file:line:message — allowing straightforward integration with text editors like vim and without adding extra dependencies to the project (relying on the quickfix-window from vim or similar feature for other editors). One can configure his editor with the following line (vim) and start jumping between failures using the regular editor keybindings, without having to visually parse the output from rspec to find out the file and line number he want to reach: ```vim autocmd FileType ruby set makeprg=bundle\ exec\ rspec\ --format\ m ```
1 parent 7727a07 commit 777d85f

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

lib/rspec/core/formatters.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module RSpec::Core::Formatters
7474
autoload :JsonFormatter, 'rspec/core/formatters/json_formatter'
7575
autoload :BisectDRbFormatter, 'rspec/core/formatters/bisect_drb_formatter'
7676
autoload :ExceptionPresenter, 'rspec/core/formatters/exception_presenter'
77+
autoload :MinimalFormatter, 'rspec/core/formatters/minimal_formatter'
7778

7879
# Register the formatter class
7980
# @param formatter_class [Class] formatter class to register
@@ -212,6 +213,8 @@ def built_in_formatter(key)
212213
JsonFormatter
213214
when 'bisect-drb'
214215
BisectDRbFormatter
216+
when 'm', 'minimal'
217+
MinimalFormatter
215218
end
216219
end
217220

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
RSpec::Support.require_rspec_core "formatters/base_formatter"
2+
3+
module RSpec
4+
module Core
5+
module Formatters
6+
# @private
7+
class MinimalFormatter < BaseFormatter
8+
Formatters.register self, :example_failed, :dump_profile, :message
9+
10+
def example_failed(failure)
11+
output.puts "#{failure.example.location}:#{failure.example.description}"
12+
end
13+
14+
# Discard profile and messages
15+
#
16+
# These outputs are not really relevant in the context of this minimal
17+
# formatter.
18+
def dump_profile(_profile); end
19+
def message(_message); end
20+
end
21+
end
22+
end
23+
end

lib/rspec/core/option_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def parser(options)
112112
' [d]ocumentation (group and example names)',
113113
' [h]tml',
114114
' [j]son',
115+
' [m]inimal (suitable for editors integration)',
115116
' custom formatter class name') do |o|
116117
options[:formatters] ||= []
117118
options[:formatters] << [o]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'rspec/core/formatters/minimal_formatter'
2+
3+
module RSpec::Core::Formatters
4+
RSpec.describe MinimalFormatter do
5+
include FormatterSupport
6+
7+
it 'produces the expected full output' do
8+
output = run_example_specs_with_formatter('minimal')
9+
expect(output).to eq(<<-EOS.gsub(/^\s+\|/, ''))
10+
|./spec/rspec/core/resources/formatter_specs.rb:4:is marked as pending but passes
11+
|./spec/rspec/core/resources/formatter_specs.rb:36:fails
12+
|./spec/rspec/core/resources/formatter_specs.rb:40:fails twice
13+
|./spec/rspec/core/resources/formatter_specs.rb:47:fails with a backtrace that has no file
14+
|./spec/rspec/core/resources/formatter_specs.rb:53:fails with a backtrace containing an erb file
15+
|./spec/rspec/core/resources/formatter_specs.rb:71:raises
16+
EOS
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)