Class: RubyLsp::RSpec::RSpecFormatter
- Inherits:
-
RSpec::Core::Formatters::ProgressFormatter
- Object
- RSpec::Core::Formatters::ProgressFormatter
- RubyLsp::RSpec::RSpecFormatter
- Defined in:
- lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb
Instance Method Summary collapse
- #adjust_backtrace(backtrace) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
- #example_started(notification) ⇒ Object
- #generate_id(example) ⇒ Object
-
#initialize(output) ⇒ RSpecFormatter
constructor
A new instance of RSpecFormatter.
- #stop(notification) ⇒ Object
- #uri_for(example) ⇒ Object
Constructor Details
#initialize(output) ⇒ RSpecFormatter
Returns a new instance of RSpecFormatter.
21 22 23 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 21 def initialize(output) super(output) end |
Instance Method Details
#adjust_backtrace(backtrace) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 80 def adjust_backtrace(backtrace) # Correct the backtrace entry so that vscode recognized it as a link to open parts = backtrace.split(":", 3) return backtrace if parts.length < 2 parts[0].sub(/^\./, "file://" + File.(".")) + ":" + parts[1] + " : " + (parts[2] || "") end |
#example_failed(notification) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 42 def example_failed(notification) super(notification) example = notification.example uri = uri_for(example) id = generate_id(example) = notification..join("\n") << "\n\n" << notification.formatted_backtrace.map(&method(:adjust_backtrace)).map { |s| "# " + s }.join("\n") RubyLsp::LspReporter.instance.record_fail(id: id, message: , uri: uri) end |
#example_passed(notification) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 33 def example_passed(notification) super(notification) example = notification.example uri = uri_for(example) id = generate_id(example) RubyLsp::LspReporter.instance.record_pass(id: id, uri: uri) end |
#example_pending(notification) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 54 def example_pending(notification) super(notification) example = notification.example uri = uri_for(example) id = generate_id(example) RubyLsp::LspReporter.instance.record_skip(id: id, uri: uri) end |
#example_started(notification) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 25 def example_started(notification) example = notification.example uri = uri_for(example) id = generate_id(example) line = example.location.split(":").last RubyLsp::LspReporter.instance.start_test(id: id, uri: uri, line: line) end |
#generate_id(example) ⇒ Object
76 77 78 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 76 def generate_id(example) [example, *example.example_group.parent_groups].reverse.map(&:location).join("::") end |
#stop(notification) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 63 def stop(notification) if RubyLsp::LspReporter.start_coverage? RubyLsp::LspReporter.instance.at_coverage_exit else RubyLsp::LspReporter.instance.shutdown end end |
#uri_for(example) ⇒ Object
71 72 73 74 |
# File 'lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb', line 71 def uri_for(example) absolute_path = File.(example.file_path) URI::Generic.from_path(path: absolute_path) end |