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

Commit 2769fb3

Browse files
committed
Add a simple C 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 simlar 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 visualy 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\ c ```
1 parent 4a29a4b commit 2769fb3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-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 :CFormatter, 'rspec/core/formatters/c_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 'c'
217+
CFormatter
215218
end
216219
end
217220

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
RSpec::Support.require_rspec_core "formatters/base_formatter"
2+
3+
module RSpec
4+
module Core
5+
module Formatters
6+
# @private
7+
class CFormatter < BaseFormatter
8+
Formatters.register self, :example_failed, :dump_profile
9+
10+
def example_failed(failure)
11+
output.puts "#{failure.example.metadata[:location]}:#{failure.example.metadata[:description]}"
12+
end
13+
14+
def dump_profile(_profile); end
15+
end
16+
end
17+
end
18+
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+
' c (minimalist output suitable for editors integration)',
115116
' custom formatter class name') do |o|
116117
options[:formatters] ||= []
117118
options[:formatters] << [o]

0 commit comments

Comments
 (0)