Skip to content

Commit

Permalink
add spec for print output
Browse files Browse the repository at this point in the history
  • Loading branch information
jbielick committed Oct 7, 2019
1 parent 64347e8 commit 4890835
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 105 deletions.
89 changes: 88 additions & 1 deletion spec/process_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
data = JSON.parse(request.body)
expect(data['conclusion']).to eq 'failure'
expect(data['output']['title']).to eq 'Pronto'
expect(data['output']['annotations'].size).to eq 17
expect(data['output']['annotations'].size).to eq 9
end.to_return(status: 200, body: '{}', headers: {})

result = ProcessResults.run(metadata: metadata, results_io: File.open('spec/results.json'))
Expand Down Expand Up @@ -84,4 +84,91 @@

end

describe '#print' do

it 'prints to stderr' do
metadata = Metadata.new(
event: JSON.parse(File.read('spec/event.json')),
sha: 'ab2c4e',
workspace: '/github/repo/workspace',
action: 'adwerx/pronto-ruby',
)
stub_request(
:post,
'https://api.github.com/repos/Codertocat/Hello-World/check-runs'
).to_return(status: 201, body: '{"id": 1}', headers: {})

stub_request(
:patch,
'https://api.github.com/repos/Codertocat/Hello-World/check-runs/1'
).to_return(status: 200, body: '{}', headers: {})
err_spy = spy('stderr', puts: true)
result = ProcessResults.run(metadata: metadata, results_io: File.open('spec/results.json'))
stub_const('STDERR', err_spy)

result.print

expect(err_spy).to have_received(:puts).with(<<~MSG)
Pronto
---
There are 9 issues raised by pronto runners.
Pronto::Rubocop warning
spec/process_results_spec.rb:88
Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:94
Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:96
Lint/UselessAssignment: Useless assignment to variable - `post_stub`.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:101
Lint/UselessAssignment: Useless assignment to variable - `patch_stub`.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:106
Metrics/LineLength: Line is too long. [97/80]
-
Pronto::Rubocop warning
spec/process_results_spec.rb:112
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:119
Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
-
Pronto::Rubocop warning
spec/process_results_spec.rb:121
Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
-
Pronto::Rubocop warning
src/process_results.rb:50
Style/StderrPuts: Use `warn` instead of `STDERR.puts` to allow such output to be disabled.
MSG
end

end

end
136 changes: 36 additions & 100 deletions spec/results.json
Original file line number Diff line number Diff line change
@@ -1,138 +1,74 @@
[
{
"level": "W",
"message": "Style/FrozenStringLiteralComment: Missing magic comment `# frozen_string_literal: true`.",
"path": "db/seeds.rb",
"line": 1,
"commit_sha": "3ce7fede7ce4f3172961bf5df79dbe8d5e2cd6eb",
"message": "Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.",
"path": "spec/process_results_spec.rb",
"line": 88,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/AlignHash: Align the elements of a hash literal if they span more than one line.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 9,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.",
"path": "spec/process_results_spec.rb",
"line": 94,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [107/100]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 9,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Lint/UselessAssignment: Useless assignment to variable - `post_stub`.",
"path": "spec/process_results_spec.rb",
"line": 96,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/AlignHash: Align the elements of a hash literal if they span more than one line.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 10,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Lint/UselessAssignment: Useless assignment to variable - `patch_stub`.",
"path": "spec/process_results_spec.rb",
"line": 101,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [107/100]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 10,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Metrics/LineLength: Line is too long. [97/80]",
"path": "spec/process_results_spec.rb",
"line": 106,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/AlignHash: Align the elements of a hash literal if they span more than one line.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 11,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.",
"path": "spec/process_results_spec.rb",
"line": 112,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [106/100]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 11,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.",
"path": "spec/process_results_spec.rb",
"line": 119,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/AlignHash: Align the elements of a hash literal if they span more than one line.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 12,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"message": "Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.",
"path": "spec/process_results_spec.rb",
"line": 121,
"commit_sha": "1cab6ad0e4de9fa4ebfa410742c51da4e57ac883",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [107/100]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 12,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/AlignHash: Align the elements of a hash literal if they span more than one line.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 13,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [106/100]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 13,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/AbcSize: Assignment Branch Condition size for _process_report_data is too high. [50.89/20]",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 56,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Style/RescueStandardError: Avoid rescuing without specifying an error class.",
"path": "lib/anx_api/anx_line_item_video_daily_stats_report.rb",
"line": 150,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [104/100]",
"path": "lib/anx_network_report_utils_module.rb",
"line": 35,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Metrics/LineLength: Line is too long. [107/100]",
"path": "lib/anx_network_report_utils_module.rb",
"line": 37,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.",
"path": "lib/anx_network_report_utils_module.rb",
"line": 130,
"commit_sha": "38c8aec9b83180656f9ca6be235f2c5cabc2a1d3",
"runner": "Pronto::Rubocop"
},
{
"level": "W",
"message": "Layout/EmptyLineAfterGuardClause: Add empty line after guard clause.",
"path": "lib/patches/seed.rb",
"line": 28,
"commit_sha": "3ce7fede7ce4f3172961bf5df79dbe8d5e2cd6eb",
"message": "Style/StderrPuts: Use `warn` instead of `STDERR.puts` to allow such output to be disabled.",
"path": "src/process_results.rb",
"line": 50,
"commit_sha": "64347e8776c393c344bafec964ab6b234d40f089",
"runner": "Pronto::Rubocop"
}
]
8 changes: 4 additions & 4 deletions src/process_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ def success?
end

def print
annotation_text = annotations.each_with_object('') do |annotation, text|
text += <<~MSG
annotation_text = output.annotations.map do |annotation|
<<~MSG
#{annotation[:title]} #{annotation[:annotation_level]}
#{annotation[:path]}:#{annotation[:start_line]}
#{annotation[:message]}
MSG
end
puts <<~MSG
STDERR.puts <<~MSG
#{output.title}
---
#{output.summary}
#{annotation_text.join("\n-")}
#{annotation_text.join("\n-\n")}
MSG
end

Expand Down

0 comments on commit 4890835

Please sign in to comment.