From 3c2467fc3d48dd008dcbfef8525fa3381acfed68 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 22 Dec 2020 18:03:01 +0000 Subject: [PATCH] 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. --- Library/Homebrew/Gemfile | 1 + Library/Homebrew/Gemfile.lock | 3 + Library/Homebrew/test/spec_helper.rb | 2 +- .../Homebrew/test/support/github_formatter.rb | 58 ------------------- 4 files changed, 5 insertions(+), 59 deletions(-) delete mode 100644 Library/Homebrew/test/support/github_formatter.rb diff --git a/Library/Homebrew/Gemfile b/Library/Homebrew/Gemfile index bc2bd31373..1004258583 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -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 diff --git a/Library/Homebrew/Gemfile.lock b/Library/Homebrew/Gemfile.lock index c358b4c716..f84562df56 100644 --- a/Library/Homebrew/Gemfile.lock +++ b/Library/Homebrew/Gemfile.lock @@ -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 diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 0652949937..1a4bf7e1a4 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -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" diff --git a/Library/Homebrew/test/support/github_formatter.rb b/Library/Homebrew/test/support/github_formatter.rb deleted file mode 100644 index 6f019f9baf..0000000000 --- a/Library/Homebrew/test/support/github_formatter.rb +++ /dev/null @@ -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