Skip to content

Commit

Permalink
Merge pull request #316 from pact-foundation/deps/rem_term-ansicolor
Browse files Browse the repository at this point in the history
Deps/rem term ansicolor
  • Loading branch information
YOU54F committed Aug 8, 2024
2 parents 43331d0 + 4f01bc9 commit ca65f27
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/pact/pact_broker/fetch_pact_uris_for_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def log_message

def handling_no_pacts_found
pacts_found = yield
raise "No pacts found to verify" if pacts_found.blank? && options[:fail_if_no_pacts_found] != false
if pacts_found.blank? && options[:fail_if_no_pacts_found] == false
raise "No pacts found to verify" if pacts_found.empty? && options[:fail_if_no_pacts_found] != false
if pacts_found.empty? && options[:fail_if_no_pacts_found] == false
Pact.configuration.output_stream.puts "WARN: No pacts found to verify & fail_if_no_pacts_found is set to false."
end
pacts_found
Expand Down
12 changes: 4 additions & 8 deletions lib/pact/provider/help/console_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
require 'fileutils'
require 'pact/consumer/configuration'
require 'pact/provider/help/write'
require 'term/ansicolor'
require 'rainbow'

module Pact
module Provider
module Help
class ConsoleText

C = ::Term::ANSIColor

def self.call reports_dir = Pact.configuration.reports_dir, options = {color: true}
new(reports_dir || Pact.configuration.reports_dir, options).call
end
Expand Down Expand Up @@ -46,13 +44,11 @@ def error_text_plain
end

def error_text_coloured
C.red(error_text_plain)
Rainbow(error_text_plain).red
end

class ColorizeMarkdown

C = ::Term::ANSIColor

def self.call markdown
markdown.split("\n").collect do | line |
if line.start_with?("# ")
Expand All @@ -66,11 +62,11 @@ def self.call markdown
end

def self.yellow_underling string
C.underline(C.yellow(string))
Rainbow(string).yellow.underline
end

def self.green string
C.green(string)
Rainbow(string).green
end

end
Expand Down
6 changes: 2 additions & 4 deletions lib/pact/provider/help/prompt_text.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'pact/consumer/configuration'
require 'term/ansicolor'
require 'rainbow'
require 'pathname'

module Pact
module Provider
module Help
class PromptText

C = ::Term::ANSIColor

def self.call reports_dir = Pact.configuration.reports_dir, options = {color: Pact.configuration.color_enabled}
new(reports_dir, options).call
end
Expand All @@ -31,7 +29,7 @@ def prompt_text_plain
end

def prompt_text_colored
C.yellow(prompt_text_plain)
Rainbow(prompt_text_plain).yellow
end

def rake_args
Expand Down
8 changes: 3 additions & 5 deletions lib/pact/provider/matchers/messages.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require 'term/ansicolor'
require 'rainbow'
require 'pact/term'

module Pact
module Matchers
module Messages

C = ::Term::ANSIColor

def match_term_failure_message diff, actual, diff_formatter, color_enabled
actual_string = String === actual ? actual : actual.to_json
maybe_coloured_string = color_enabled ? C.white(actual_string) : actual_string
maybe_coloured_string = color_enabled ? Rainbow(actual_string).white : actual_string
message = "Actual: #{maybe_coloured_string}\n\n"
formatted_diff = diff_formatter.call(diff)
message + colorize_if_enabled(formatted_diff, color_enabled)
Expand Down Expand Up @@ -40,7 +38,7 @@ def colorize_if_enabled formatted_diff, color_enabled
# RSpec wraps each line in the failure message with failure_color, turning it red.
# To ensure the lines in the diff that should be white, stay white, put an
# ANSI reset at the start of each line.
formatted_diff.split("\n").collect{ |line| ::Term::ANSIColor.reset + line }.join("\n")
formatted_diff.split("\n").collect{ |line|"\e[0m#{line}" }.join("\n")
else
formatted_diff
end
Expand Down
8 changes: 3 additions & 5 deletions lib/pact/provider/print_missing_provider_states.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require 'term/ansicolor'
require 'rainbow'

module Pact
module Provider
class PrintMissingProviderStates

C = ::Term::ANSIColor

# Hash of consumer names to array of names of missing provider states
def self.call missing_provider_states, output
if missing_provider_states.any?
Expand All @@ -15,8 +13,8 @@ def self.call missing_provider_states, output

def self.colorize string
lines = string.split("\n")
first_line = C.cyan(C.underline(lines[0]))
other_lines = C.cyan(lines[1..-1].join("\n"))
first_line = Rainbow(lines[0]).cyan.underline
other_lines = Rainbow(lines[1..-1].join("\n")).cyan
first_line + "\n" + other_lines
end

Expand Down
4 changes: 1 addition & 3 deletions lib/pact/provider/rspec/formatter_rspec_2.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pact/provider/print_missing_provider_states'
require 'rspec/core/formatters/documentation_formatter'
require 'term/ansicolor'
require 'rainbow'
require 'pact/provider/help/prompt_text'

module Pact
Expand All @@ -13,8 +13,6 @@ def dump_commands_to_rerun_failed_examples
end
end

C = ::Term::ANSIColor

def dump_commands_to_rerun_failed_examples
return if failed_examples.empty?

Expand Down
4 changes: 1 addition & 3 deletions lib/pact/provider/rspec/formatter_rspec_3.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'pact/provider/print_missing_provider_states'
require 'rspec/core/formatters'
require 'term/ansicolor'
require 'rainbow'
require 'pact/provider/help/prompt_text'

module Pact
Expand All @@ -22,8 +22,6 @@ def dump_summary(summary)
:example_passed, :example_pending, :example_failed
end

C = ::Term::ANSIColor

def example_group_started(notification)
# This is the metadata on the top level "Verifying a pact between X and Y" describe block
if @group_level == 0
Expand Down
4 changes: 2 additions & 2 deletions lib/pact/provider/rspec/pact_broker_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rspec/core/formatters'
require 'pact/provider/verification_results/publish_all'
require 'term/ansicolor'
require 'rainbow'
require 'pact/matchers/extract_diff_messages'

module Pact
Expand Down Expand Up @@ -43,7 +43,7 @@ def format_example(example)
if example.exception
hash[:exception] = {
class: example.exception.class.name,
message: ::Term::ANSIColor.uncolor(example.exception.message)
message: "\e[0m#{example.exception.message}"
}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/pact.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace :pact do

desc "Verifies the pact at the given URI against this service provider."
task 'verify:at', :pact_uri do | t, args |
require 'term/ansicolor'
require 'rainbow'
require 'pact/tasks/task_helper'

include Pact::TaskHelper

abort(::Term::ANSIColor.red("Please provide a pact URI. eg. rake pact:verify:at[../my-consumer/spec/pacts/my_consumer-my_provider.json]")) unless args[:pact_uri]
abort(Rainbow("Please provide a pact URI. eg. rake pact:verify:at[../my-consumer/spec/pacts/my_consumer-my_provider.json]").red) unless args[:pact_uri]
handle_verification_failure do
execute_pact_verify args[:pact_uri]
end
Expand Down
2 changes: 1 addition & 1 deletion pact.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'rack-test', '>= 0.6.3', '< 3.0.0'
gem.add_runtime_dependency 'thor', '>= 0.20', '< 2.0'
gem.add_runtime_dependency 'webrick', '~> 1.8'
gem.add_runtime_dependency 'term-ansicolor', '~> 1.7'
gem.add_runtime_dependency "rainbow", '~> 3.1'

gem.add_runtime_dependency 'pact-support', '~> 1.16', '>= 1.16.9'
gem.add_runtime_dependency 'pact-mock_service', '~> 3.0', '>= 3.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module PactBroker

context "when the beta:provider-pacts-for-verification relation does not exist" do
before do
allow(FetchPacts).to receive(:call)
allow(FetchPacts).to receive(:call).and_return([])
stub_request(:get, "http://broker.org/").to_return(status: 200, body: response_body, headers: response_headers)
end

Expand Down
5 changes: 2 additions & 3 deletions spec/lib/pact/provider/matchers/messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ module Matchers
let(:diff_formatter) { Pact::Matchers::UnixDiffFormatter }
let(:message) { "line1\nline2"}
let(:output_message) { "Actual: actual\n\n#{message}"}
let(:output_message_with_resets) { "Actual: \e[37mactual\e[0m\n\n#{r}line1\n#{r}line2"}
let(:r) { ::Term::ANSIColor.reset }
let(:r) { "\e[0m" }
let(:output_message_with_resets) { "Actual: \e[37mactual#{r}\n\n#{r}line1\n#{r}line2"}
let(:diff) { double("diff") }
let(:actual) { "actual" }
let(:color_enabled) { true }
let(:ansi_reset_at_start_of_line) { /^#{Regexp.escape ::Term::ANSIColor.reset}/ }
let(:message_line_count) { message.split("\n").size }

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/support/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def execute_command command, options = {}
end

def ensure_patterns_present command, options, output
require 'term/ansicolor'
require 'rainbow'
options[:with].each do | pattern |
raise ("Could not find #{pattern.inspect} in output of #{command}" + "\n\n#{output}") unless output =~ pattern
end
end

def ensure_patterns_not_present command, options, output
require 'term/ansicolor'
require 'rainbow'
options[:without].each do | pattern |
raise ("Expected not to find #{pattern.inspect} in output of #{command}" + "\n\n#{output}") if output =~ pattern
end
Expand Down
4 changes: 2 additions & 2 deletions tasks/pact-test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ namespace :pact do
end

def ensure_patterns_present command, options, stdout, stderr
require 'term/ansicolor'
require 'rainbow'
output = stdout.read + stderr.read
options[:with].each do | pattern |
raise (::Term::ANSIColor.red("Could not find #{pattern.inspect} in output of #{command}") + "\n\n#{output}") unless output =~ pattern
raise (Rainbow("Could not find #{pattern.inspect} in output of #{command}").red + "\n\n#{output}") unless output =~ pattern
end
end
end

0 comments on commit ca65f27

Please sign in to comment.