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
7 changed files
with
138 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
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
require "colorize" | ||
|
||
class NextRails::BundleReport::RubyVersionCompatibility | ||
attr_reader :gems, :options | ||
|
||
VALID_RUBY_VERSIONS = (1.9..3.4).step(0.1).to_a.freeze | ||
|
||
def initialize(gems: NextRails::GemInfo.all, options: nil) | ||
@gems = gems | ||
@options = options | ||
end | ||
|
||
def generate | ||
return invalid_message unless valid? | ||
|
||
message | ||
end | ||
|
||
private | ||
|
||
def message | ||
output = "=> Incompatible gems with Ruby #{ruby_version}:\n".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: #{ruby_version}. Valid versions are: #{VALID_RUBY_VERSIONS.join(', ')}".white.bold | ||
end | ||
|
||
def valid? | ||
VALID_RUBY_VERSIONS.include?(ruby_version) | ||
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
68 changes: 68 additions & 0 deletions
68
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,68 @@ | ||
# 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" | ||
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 "2 gems incompatible with Ruby 2.7" | ||
end | ||
end | ||
end | ||
end |