Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [BUGFIX: example](https://github.com/fastruby/next_rails/pull/<number>)

- [CHORE: Drop `rainbow` gem dependency in favor of a native `NextRails::Tint` ANSI wrapper](https://github.com/fastruby/next_rails/pull/183)
- [BUGFIX: Compare mode now checks only buckets the current process ran, fixing parallel test support](https://github.com/fastruby/next_rails/pull/179)
- [FEATURE: Add `deprecations merge` command to combine parallel CI shards](https://github.com/fastruby/next_rails/pull/177)
- [FEATURE: Add parallel CI support for DeprecationTracker](https://github.com/fastruby/next_rails/pull/176)
Expand Down
4 changes: 2 additions & 2 deletions lib/deprecation_tracker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rainbow"
require "next_rails/tint"
require "json"

# A shitlist for deprecation warnings during test runs. It has two modes: "save" and "compare"
Expand Down Expand Up @@ -209,7 +209,7 @@ def compare
See \e[4;37mdev-docs/testing/deprecation_tracker.md\e[0;31m for more information.
MESSAGE

raise UnexpectedDeprecations, Rainbow(message).red
raise UnexpectedDeprecations, NextRails::Tint(message).red
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/next_rails/bundle_report.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rainbow"
require "next_rails/tint"
require "cgi"
require "erb"
require "json"
Expand Down Expand Up @@ -105,14 +105,14 @@ def output_to_stdout(out_of_date_gems, total_gem_count, sourced_from_git_count)
header = "#{gem.name} #{gem.version}"

puts <<-MESSAGE
#{Rainbow(header).bold.white}: released #{gem.age} (latest version, #{gem.latest_version.version}, released #{gem.latest_version.age})
#{NextRails::Tint(header).bold.white}: released #{gem.age} (latest version, #{gem.latest_version.version}, released #{gem.latest_version.age})
MESSAGE
end

percentage_out_of_date = ((out_of_date_gems.count / total_gem_count.to_f) * 100).round
footer = <<-MESSAGE
#{Rainbow(sourced_from_git_count.to_s).yellow} gems are sourced from git
#{Rainbow(out_of_date_gems.count.to_s).red} of the #{total_gem_count} gems are out-of-date (#{percentage_out_of_date}%)
#{NextRails::Tint(sourced_from_git_count.to_s).yellow} gems are sourced from git
#{NextRails::Tint(out_of_date_gems.count.to_s).red} of the #{total_gem_count} gems are out-of-date (#{percentage_out_of_date}%)
MESSAGE

puts ''
Expand Down
3 changes: 2 additions & 1 deletion lib/next_rails/bundle_report/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "optparse"
require "next_rails"
require "next_rails/bundle_report"
require "next_rails/tint"

class NextRails::BundleReport::CLI
def initialize(argv)
Expand Down Expand Up @@ -89,7 +90,7 @@ def parse_options
begin
option_parser.parse!(@argv)
rescue OptionParser::ParseError => e
warn Rainbow(e.message).red
warn NextRails::Tint(e.message).red
puts option_parser
exit 1
end
Expand Down
24 changes: 13 additions & 11 deletions lib/next_rails/bundle_report/rails_version_compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "next_rails/tint"

class NextRails::BundleReport::RailsVersionCompatibility
def initialize(gems: NextRails::GemInfo.all, options: {})
@gems = gems
Expand All @@ -20,34 +22,34 @@ def incompatible_gems_by_state
def erb_output
template = <<-ERB
<% if incompatible_gems_by_state[:found_compatible] -%>
<%= Rainbow("=> Incompatible with Rails #{rails_version} (with new versions that are compatible):").white.bold %>
<%= Rainbow("These gems will need to be upgraded before upgrading to Rails #{rails_version}.").italic %>
<%= NextRails::Tint("=> Incompatible with Rails #{rails_version} (with new versions that are compatible):").white.bold %>
<%= NextRails::Tint("These gems will need to be upgraded before upgrading to Rails #{rails_version}.").italic %>

<% incompatible_gems_by_state[:found_compatible].each do |gem| -%>
<%= gem_header(gem) %> - upgrade to <%= gem.latest_compatible_version.version %>
<% end -%>

<% end -%>
<% if incompatible_gems_by_state[:incompatible] -%>
<%= Rainbow("=> Incompatible with Rails #{rails_version} (with no new compatible versions):").white.bold %>
<%= Rainbow("These gems will need to be removed or replaced before upgrading to Rails #{rails_version}.").italic %>
<%= NextRails::Tint("=> Incompatible with Rails #{rails_version} (with no new compatible versions):").white.bold %>
<%= NextRails::Tint("These gems will need to be removed or replaced before upgrading to Rails #{rails_version}.").italic %>

<% incompatible_gems_by_state[:incompatible].each do |gem| -%>
<%= gem_header(gem) %> - new version, <%= gem.latest_version.version %>, is not compatible with Rails #{rails_version}
<% end -%>

<% end -%>
<% if incompatible_gems_by_state[:no_new_version] -%>
<%= Rainbow("=> Incompatible with Rails #{rails_version} (with no new versions):").white.bold %>
<%= Rainbow("These gems will need to be upgraded by us or removed before upgrading to Rails #{rails_version}.").italic %>
<%= Rainbow("This list is likely to contain internal gems, like Cuddlefish.").italic %>
<%= NextRails::Tint("=> Incompatible with Rails #{rails_version} (with no new versions):").white.bold %>
<%= NextRails::Tint("These gems will need to be upgraded by us or removed before upgrading to Rails #{rails_version}.").italic %>
<%= NextRails::Tint("This list is likely to contain internal gems, like Cuddlefish.").italic %>

<% incompatible_gems_by_state[:no_new_version].each do |gem| -%>
<%= gem_header(gem) %> - new version not found
<% end -%>

<% end -%>
<%= Rainbow(incompatible_gems.length.to_s).red %> gems incompatible with Rails <%= rails_version %>
<%= NextRails::Tint(incompatible_gems.length.to_s).red %> gems incompatible with Rails <%= rails_version %>
ERB

erb_version = ERB.version
Expand All @@ -63,9 +65,9 @@ def erb_output
end

def gem_header(_gem)
header = Rainbow("#{_gem.name} #{_gem.version}").bold
header << Rainbow(" (loaded from git)").magenta if _gem.sourced_from_git?
header
parts = [NextRails::Tint("#{_gem.name} #{_gem.version}").bold]
parts << NextRails::Tint(" (loaded from git)").magenta if _gem.sourced_from_git?
parts.join
end

def incompatible_gems
Expand Down
18 changes: 9 additions & 9 deletions lib/next_rails/bundle_report/ruby_version_compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rainbow"
require "next_rails/tint"

class NextRails::BundleReport::RubyVersionCompatibility
MINIMAL_VERSION = 1.0
Expand All @@ -10,20 +10,20 @@ def initialize(gems: NextRails::GemInfo.all, options: {})
end

def generate
return invalid_message unless valid?

message
(valid? ? message : invalid_message).to_s
end

private

def message
output = Rainbow("=> Incompatible gems with Ruby #{ruby_version}:").white.bold
noun = incompatible.one? ? "gem" : "gems"
parts = [NextRails::Tint("=> Incompatible gems with Ruby #{ruby_version}:").white.bold]
incompatible.each do |gem|
output += Rainbow("\n#{gem.name} - required Ruby version: #{gem.gem_specification.required_ruby_version}").magenta
parts << NextRails::Tint("#{gem.name} - required Ruby version: #{gem.gem_specification.required_ruby_version}").magenta
end
output += Rainbow("\n\n#{incompatible.length} incompatible #{incompatible.one? ? 'gem' : 'gems' } with Ruby #{ruby_version}").red
output
parts << ""
parts << NextRails::Tint("#{incompatible.length} incompatible #{noun} with Ruby #{ruby_version}").red
parts.join("\n")
end

def incompatible
Expand All @@ -35,7 +35,7 @@ def ruby_version
end

def invalid_message
Rainbow("=> Invalid Ruby version: #{options[:ruby_version]}.").red.bold
NextRails::Tint("=> Invalid Ruby version: #{options[:ruby_version]}.").red.bold
end

def valid?
Expand Down
47 changes: 47 additions & 0 deletions lib/next_rails/tint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module NextRails
# Lightweight ANSI color/style wrapper with chainable style methods.
# Wrap a string with `NextRails::Tint("text")` then chain styles:
#
# NextRails::Tint("hello").red.bold
#
# Instances are effectively immutable: each style method returns a new
# `Tint` rather than mutating the receiver, so a reference can be reused
# without styles accumulating across chains.
class Tint
CODES = {
bold: 1,
italic: 3,
red: 31,
green: 32,
yellow: 33,
blue: 34,
magenta: 35,
cyan: 36,
white: 37
}.freeze

def initialize(string, codes = [])
@string = string.to_s
@codes = codes
end

CODES.each_key do |style|
define_method(style) do
self.class.new(@string, @codes + [CODES[style]])
end
end

def to_s
return @string if @codes.empty?

"\e[#{@codes.join(";")}m#{@string}\e[0m"
end
alias_method :to_str, :to_s
end

def self.Tint(string)
Tint.new(string)
end
end
1 change: 0 additions & 1 deletion next_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "rainbow", ">= 3"
spec.add_development_dependency "bundler", ">= 1.16"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
16 changes: 16 additions & 0 deletions spec/deprecation_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@

expect { subject.compare }.to raise_error(DeprecationTracker::UnexpectedDeprecations, /Deprecation warnings have changed/)
end

it "wraps the raised message with red ANSI escape codes" do
setup_tracker = DeprecationTracker.new(shitlist_path)
setup_tracker.bucket = "bucket 1"
setup_tracker.add("a")
setup_tracker.save

subject = DeprecationTracker.new(shitlist_path)
subject.bucket = "bucket 1"
subject.add("b")

expect { subject.compare }.to raise_error(DeprecationTracker::UnexpectedDeprecations) do |error|
expect(error.message).to start_with("\e[31m")
expect(error.message).to end_with("\e[0m")
end
end
end

describe "#save" do
Expand Down
10 changes: 5 additions & 5 deletions spec/next_rails/bundle_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "rainbow"
require "next_rails/tint"
require "spec_helper"

RSpec.describe NextRails::BundleReport do
Expand Down Expand Up @@ -30,14 +30,14 @@
it 'invokes $stdout.puts properly', :aggregate_failures do
allow($stdout)
.to receive(:puts)
.with("#{Rainbow('alpha 0.0.1').bold.white}: released #{alpha_age} (latest version, 0.0.2, released #{bravo_age})\n")
.with("#{NextRails::Tint('alpha 0.0.1').bold.white}: released #{alpha_age} (latest version, 0.0.2, released #{bravo_age})\n")
allow($stdout)
.to receive(:puts)
.with("#{Rainbow('bravo 0.2.0').bold.white}: released #{bravo_age} (latest version, 0.2.2, released #{charlie_age})\n")
.with("#{NextRails::Tint('bravo 0.2.0').bold.white}: released #{bravo_age} (latest version, 0.2.2, released #{charlie_age})\n")
allow($stdout).to receive(:puts).with('')
allow($stdout).to receive(:puts).with(<<-EO_MULTLINE_STRING)
#{Rainbow('1').yellow} gems are sourced from git
#{Rainbow('2').red} of the 2 gems are out-of-date (100%)
#{NextRails::Tint('1').yellow} gems are sourced from git
#{NextRails::Tint('2').red} of the 2 gems are out-of-date (100%)
EO_MULTLINE_STRING
end
end
Expand Down
34 changes: 34 additions & 0 deletions spec/next_rails/tint_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "next_rails/tint"
require "spec_helper"

RSpec.describe NextRails::Tint do
it "returns the plain string when no styles are applied" do
expect(NextRails::Tint("hello").to_s).to eq("hello")
end

it "wraps the string with a single ANSI code" do
expect(NextRails::Tint("hello").red.to_s).to eq("\e[31mhello\e[0m")
end

it "chains multiple styles into one escape sequence" do
expect(NextRails::Tint("hello").bold.white.to_s).to eq("\e[1;37mhello\e[0m")
end

it "interpolates cleanly into another string" do
expect("hi #{NextRails::Tint('there').green}!").to eq("hi \e[32mthere\e[0m!")
end

it "joins with other Tints via Array#join through to_str coercion" do
joined = [NextRails::Tint("a").red, NextRails::Tint("b").green].join
expect(joined).to eq("\e[31ma\e[0m\e[32mb\e[0m")
end

it "does not accumulate codes across chains on a shared instance" do
base = NextRails::Tint("hi")
expect(base.red.to_s).to eq("\e[31mhi\e[0m")
expect(base.bold.to_s).to eq("\e[1mhi\e[0m")
expect(base.to_s).to eq("hi")
end
end
Loading