Replace test/support/github_formatter with rspec-github gem

- This was a TODO in `test/support/github_formatter.rb` and the PR it
  referenced had been merged.
This commit is contained in:
Issy Long 2020-12-22 18:03:01 +00:00
parent fc305cc9e0
commit 3c2467fc3d
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
4 changed files with 5 additions and 59 deletions

View File

@ -9,6 +9,7 @@ gem "nokogiri", require: false
gem "parallel_tests", require: false
gem "ronn", require: false
gem "rspec", require: false
gem "rspec-github", require: false
gem "rspec-its", require: false
gem "rspec-retry", require: false
gem "rspec-sorbet", require: false

View File

@ -88,6 +88,8 @@ GEM
rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-github (2.3.1)
rspec-core (~> 3.0)
rspec-its (1.3.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
@ -175,6 +177,7 @@ DEPENDENCIES
plist
ronn
rspec
rspec-github
rspec-its
rspec-retry
rspec-sorbet

View File

@ -24,6 +24,7 @@ if ENV["HOMEBREW_TESTS_COVERAGE"]
end
require "rspec/its"
require "rspec/github"
require "rspec/wait"
require "rspec/retry"
require "rspec/sorbet"
@ -38,7 +39,6 @@ $LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/suppo
require_relative "../global"
require "test/support/no_seed_progress_formatter"
require "test/support/github_formatter"
require "test/support/helper/cask"
require "test/support/helper/fixtures"
require "test/support/helper/formula"

View File

@ -1,58 +0,0 @@
# typed: true
# frozen_string_literal: true
require "rspec/core"
require "rspec/core/formatters/base_formatter"
# TODO: Replace with `rspec-github` when https://github.com/Drieam/rspec-github/pull/4 is merged.
module RSpec
module Github
class Formatter < RSpec::Core::Formatters::BaseFormatter
RSpec::Core::Formatters.register self, :example_failed, :example_pending
def self.escape(string)
# See https://github.community/t/set-output-truncates-multiline-strings/16852/3.
string.gsub("%", "%25")
.gsub("\n", "%0A")
.gsub("\r", "%0D")
end
def self.relative_path(path)
if (workspace = ENV["GITHUB_WORKSPACE"])
workspace = "#{File.realpath(workspace)}#{File::SEPARATOR}"
absolute_path = File.realpath(path)
return absolute_path.delete_prefix(workspace) if absolute_path.start_with?(workspace)
end
path
end
def example_failed(failure)
file, line = failure.example.location.split(":")
file = self.class.relative_path(file)
description = failure.example.full_description
message = failure.message_lines.join("\n")
annotation = "#{description}\n\n#{message}"
output.puts "\n::error file=#{file},line=#{line}::#{self.class.escape(annotation)}"
end
def example_pending(pending)
file, line = pending.example.location.split(":")
file = self.class.relative_path(file)
description = pending.example.full_description
message = if pending.example.skip
"Skipped: #{pending.example.execution_result.pending_message}"
else
"Pending: #{pending.example.execution_result.pending_message}"
end
annotation = "#{description}\n\n#{message}"
output.puts "\n::warning file=#{file},line=#{line}::#{self.class.escape(annotation)}"
end
end
end
end