forked from clio/ten_years_rails
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Support compatibility for Ruby versions
the `bundle_report compatibility` now supports the `--ruby-version` flag to ask it for incompatible gems with the given Ruby version. Closes #17 Closes #115
- Loading branch information
Showing
8 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
lib/next_rails/bundle_report/ruby_version_compatibility.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "colorize" | ||
|
||
class NextRails::BundleReport::RubyVersionCompatibility | ||
attr_reader :gems, :options | ||
|
||
def initialize(gems: NextRails::GemInfo.all, options: {}) | ||
@gems = gems | ||
@options = options | ||
end | ||
|
||
def generate | ||
return invalid_message unless valid? | ||
|
||
message | ||
end | ||
|
||
private | ||
|
||
def message | ||
output = "=> Incompatible gems with Ruby #{ruby_version}:".white.bold | ||
incompatible.each do |gem| | ||
output += "\n#{gem.name} - required Ruby version: #{gem.gem_specification.required_ruby_version}".magenta | ||
end | ||
output += "\n\n#{incompatible.length} gems incompatible with Ruby #{ruby_version}".red | ||
output | ||
end | ||
|
||
def incompatible | ||
gems.reject { |gem| gem.compatible_with_ruby?(ruby_version) } | ||
end | ||
|
||
def ruby_version | ||
options[:ruby_version].to_f | ||
end | ||
|
||
def invalid_message | ||
"=> Invalid Ruby version: #{options[:ruby_version]}.".red.bold | ||
end | ||
|
||
def valid? | ||
ruby_version > 1.0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
spec/next_rails/bundle_report/ruby_version_compatibility_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "next_rails/bundle_report/ruby_version_compatibility" | ||
|
||
RSpec.describe NextRails::BundleReport::RubyVersionCompatibility do | ||
let(:ruby_3_0_gem) do | ||
Gem::Specification.new do |s| | ||
s.name = "ruby_3_0_gem" | ||
s.version = "1.0.0" | ||
s.required_ruby_version = ">= 3.0" | ||
end | ||
end | ||
|
||
let(:ruby_2_5_gem) do | ||
Gem::Specification.new do |s| | ||
s.name = "ruby_2_5_gem" | ||
s.version = "1.0.0" | ||
s.required_ruby_version = ">= 2.5" | ||
end | ||
end | ||
|
||
let(:ruby_2_3_to_2_5_gem) do | ||
Gem::Specification.new do |s| | ||
s.name = "ruby_2_3_to_2_5_gem" | ||
s.version = "1.0.0" | ||
s.required_ruby_version = [">= 2.3", "< 2.5"] | ||
end | ||
end | ||
|
||
let(:no_ruby_version_gem) do | ||
Gem::Specification.new do |s| | ||
s.name = "no_ruby_version_gem" | ||
s.version = "1.0.0" | ||
end | ||
end | ||
|
||
describe "#generate" do | ||
let(:gems) do | ||
[ | ||
NextRails::GemInfo.new(ruby_3_0_gem), | ||
NextRails::GemInfo.new(ruby_2_5_gem), | ||
NextRails::GemInfo.new(ruby_2_3_to_2_5_gem), | ||
NextRails::GemInfo.new(no_ruby_version_gem) | ||
] | ||
end | ||
|
||
context "with invalid ruby version" do | ||
it "returns invalid message" do | ||
options = { ruby_version: "hola" } | ||
|
||
result = described_class.new(gems: gems, options: options).generate | ||
expect(result).to include "Invalid Ruby version: hola" | ||
end | ||
end | ||
|
||
context "with valid ruby version" do | ||
it "returns 2 incompatible gems" do | ||
options = { ruby_version: "2.7" } | ||
|
||
result = described_class.new(gems: gems, options: options).generate | ||
|
||
expect(result).to include "Incompatible gems with Ruby 2.7" | ||
expect(result).to include "ruby_3_0_gem - required Ruby version: >= 3.0" | ||
expect(result).to include "ruby_2_3_to_2_5_gem - required Ruby version:" # >= 2.3, < 2.5" | ||
expect(result).to include "2 gems incompatible with Ruby 2.7" | ||
end | ||
end | ||
end | ||
end |