Class: RspecSonarqubeFormatter
- Inherits:
-
Object
- Object
- RspecSonarqubeFormatter
- Defined in:
- lib/rspec_sonarqube_formatter.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #clean_string(input) ⇒ Object
- #duration(example) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_passed(notification) ⇒ Object
- #example_pending(notification) ⇒ Object
- #example_started(_notification) ⇒ Object
-
#initialize(output) ⇒ RspecSonarqubeFormatter
constructor
A new instance of RspecSonarqubeFormatter.
- #start(_notification) ⇒ Object
- #stop(_notification) ⇒ Object
Constructor Details
#initialize(output) ⇒ RspecSonarqubeFormatter
Returns a new instance of RspecSonarqubeFormatter.
11 12 13 14 15 |
# File 'lib/rspec_sonarqube_formatter.rb', line 11 def initialize(output) @output = output @current_file = '' @last_failure_index = 0 end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/rspec_sonarqube_formatter.rb', line 6 def output @output end |
Instance Method Details
#clean_string(input) ⇒ Object
56 57 58 |
# File 'lib/rspec_sonarqube_formatter.rb', line 56 def clean_string(input) HTMLEntities.new.encode input.to_s.gsub(/\e\[\d;*\d*m/, '').tr('"', "'") end |
#duration(example) ⇒ Object
60 61 62 |
# File 'lib/rspec_sonarqube_formatter.rb', line 60 def duration(example) (example.execution_result.run_time.to_f * 1000).round end |
#example_failed(notification) ⇒ Object
44 45 46 47 48 |
# File 'lib/rspec_sonarqube_formatter.rb', line 44 def example_failed(notification) @output.puts " <testCase name=\"#{clean_string(notification.example.description)}\" duration=\"#{duration(notification.example)}\">" @output.puts " <failure message=\"#{clean_string(notification.exception)}\" stacktrace=\"#{clean_string(notification.example.location)}\" />" @output.puts ' </testCase>' end |
#example_group_started(notification) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rspec_sonarqube_formatter.rb', line 27 def example_group_started(notification) return if notification.group.[:file_path] == @current_file @output.puts ' </file>' if @current_file != '' @output.puts " <file path=\"#{notification.group.[:file_path]}\">" @current_file = notification.group.[:file_path] end |
#example_passed(notification) ⇒ Object
40 41 42 |
# File 'lib/rspec_sonarqube_formatter.rb', line 40 def example_passed(notification) @output.puts " <testCase name=\"#{clean_string(notification.example.description)}\" duration=\"#{duration(notification.example)}\" />" end |
#example_pending(notification) ⇒ Object
50 51 52 53 54 |
# File 'lib/rspec_sonarqube_formatter.rb', line 50 def example_pending(notification) @output.puts " <testCase name=\"#{clean_string(notification.example.description)}\" duration=\"#{duration(notification.example)}\">" @output.puts " <skipped message=\"#{clean_string(notification.example.execution_result.)}\" />" @output.puts ' </testCase>' end |
#example_started(_notification) ⇒ Object
36 37 38 |
# File 'lib/rspec_sonarqube_formatter.rb', line 36 def example_started(_notification) # Do nothing end |
#start(_notification) ⇒ Object
17 18 19 20 |
# File 'lib/rspec_sonarqube_formatter.rb', line 17 def start(_notification) @output.puts '<?xml version="1.0" encoding="UTF-8"?>' @output.puts '<testExecutions version="1">' end |
#stop(_notification) ⇒ Object
22 23 24 25 |
# File 'lib/rspec_sonarqube_formatter.rb', line 22 def stop(_notification) @output.puts ' </file>' if @current_file != '' @output.puts '</testExecutions>' end |