lib/fitting/report/console.rb in fitting-2.18.2 vs lib/fitting/report/console.rb in fitting-2.18.3
- old
+ new
@@ -1,31 +1,51 @@
+require 'terminal-table'
+
module Fitting
module Report
class Console
def initialize(tests_without_prefixes, prefixes_details)
@tests_without_prefixes = tests_without_prefixes
@prefixes_details = prefixes_details
+
@good = true
@tests_without_actions = []
@tests_without_responses = []
end
def output
- doc_res = @prefixes_details.inject('') do |res, prefix_details|
- res += "#{prefix_details[:name]}\n"
- @tests_without_actions += prefix_details[:actions][:tests_without_actions]
- res += prefix_details[:actions][:actions_details].inject('') do |res_actions, action|
- res_actions += "#{action[:method]}\t#{action[:path]}"
- tab = "\t" * (8 - action[:path].size / 8)
- @tests_without_responses += action[:responses][:tests_without_responses]
- res_actions += tab + action[:responses][:responses_details].inject('') do |res_responses, response|
- @good = false if response[:combinations][:cover_percent] != '100%'
- res_responses += " #{response[:combinations][:cover_percent]} #{response[:method]}"
+ tables = []
+
+ @prefixes_details.each do |prefix_details|
+ title = prefix_details[:name]
+ @tests_without_actions += prefix_details[:actions][:tests_without_actions] # непонятно что такое
+
+ next if prefix_details[:actions][:actions_details].count.zero?
+
+ tables << Terminal::Table.new do |t|
+ t.title = title
+ t.headings = %w[method path cover]
+
+ prefix_details[:actions][:actions_details].each do |action|
+ @tests_without_responses += action[:responses][:tests_without_responses]
+
+ path_details = action[:responses][:responses_details].map do |responses_detail|
+ @good = false if responses_detail[:combinations][:cover_percent] != '100%'
+ [responses_detail[:combinations][:cover_percent], responses_detail[:method]]
+ end.join(' ')
+
+ t.add_row [action[:method], action[:path], path_details]
end
- res_actions += "\n"
+
+ t.style = { all_separators: true, border: :unicode }
end
end
- doc_res += "\n"
+
+ tables
+ end
+
+ def output_sum
+ doc_res = ''
doc_res += "tests_without_prefixes: #{@tests_without_prefixes.size}\n"
doc_res += "tests_without_actions: #{@tests_without_actions.size}\n"
doc_res += "tests_without_responses: #{@tests_without_responses.size}\n"
end