Skip to content

Commit

Permalink
Add specs for ruby bundle resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Nov 3, 2022
1 parent 056febf commit 058a4bd
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 36 deletions.
8 changes: 8 additions & 0 deletions cobra_commander-ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require:
- rubocop-powerhome

Rails:
Enabled: false

Gemspec/RequireMFA:
Enabled: false
3 changes: 0 additions & 3 deletions cobra_commander-ruby/.standard.yml

This file was deleted.

8 changes: 2 additions & 6 deletions cobra_commander-ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

source "https://rubygems.org"

# Specify your gem's dependencies in cobra_commander-ruby.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "standard", "~> 1.3"
bundler_version = ENV.fetch("BUNDLER_VERSION", "2")
gem "bundler", "~> #{bundler_version}"
68 changes: 56 additions & 12 deletions cobra_commander-ruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,38 @@ PATH
remote: .
specs:
cobra_commander-ruby (0.1.0)
bundler

GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
coderay (1.1.3)
concurrent-ruby (1.1.10)
diff-lcs (1.5.0)
json (2.6.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
license_finder (7.0.1)
bundler
rubyzip (>= 1, < 3)
thor (~> 1.2)
tomlrb (>= 1.3, < 2.1)
with_env (= 1.1.0)
xml-simple (~> 1.1.9)
method_source (1.0.0)
minitest (5.16.3)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (3.0.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.0)
Expand All @@ -29,35 +51,57 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.35.1)
json (~> 2.3)
rubocop (1.30.1)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.18.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.23.0)
parser (>= 3.1.1.0)
rubocop-performance (1.14.3)
rubocop-performance (1.15.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-powerhome (0.5.0)
rubocop
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
rubocop-rails (2.15.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.11.1)
rubocop (~> 1.19)
ruby-progressbar (1.11.0)
standard (1.16.1)
rubocop (= 1.35.1)
rubocop-performance (= 1.14.3)
rubyzip (2.3.2)
thor (1.2.1)
tomlrb (2.0.3)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
with_env (1.1.0)
xml-simple (1.1.9)
rexml

PLATFORMS
arm64-darwin-22

DEPENDENCIES
bundler (~> 2.3.14)
cobra_commander-ruby!
rake (~> 13.0)
rspec (~> 3.0)
standard (~> 1.3)
license_finder (>= 7.0)
pry
rake (>= 12.3.3)
rspec (~> 3.5)
rubocop (= 1.30.1)
rubocop-powerhome (>= 0.5.0)

BUNDLED WITH
2.3.14
6 changes: 3 additions & 3 deletions cobra_commander-ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rubocop/rake_task"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop)

require "standard/rake"

task default: %i[spec standard]
task default: %i[spec rubocop]
10 changes: 10 additions & 0 deletions cobra_commander-ruby/cobra_commander-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ Gem::Specification.new do |spec|
end
end
spec.require_paths = ["lib"]

spec.add_dependency "bundler"

spec.add_development_dependency "bundler"
spec.add_development_dependency "license_finder", ">= 7.0"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake", ">= 12.3.3"
spec.add_development_dependency "rspec", "~> 3.5"
spec.add_development_dependency "rubocop", "1.30.1"
spec.add_development_dependency "rubocop-powerhome", ">= 0.5.0"
end
9 changes: 9 additions & 0 deletions cobra_commander-ruby/doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- - :inherit_from
- https://raw.githubusercontent.com/powerhome/oss-guide/master/license_rules.yml
- - :approve
- bundler
- :who: Carlos Palhares <carlos.palhares@powerhrg.com>
:why: 'Bundler <https://rubygems.org/gems/bundler/versions/1.17.3> is licensed under MIT, but license_finder sometimes fails to resolve that with 1.17.3.'
:versions: [1.17.3]
:when: 2022-11-02 20:36:55.617698000 Z
18 changes: 13 additions & 5 deletions cobra_commander-ruby/lib/cobra_commander/ruby/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ def initialize(root)
end

def root
Package.new(path: path, dependencies: lockfile.dependencies.values)
Package.new(path: path, dependencies: specs.map(&:name))
end

def packages
@packages ||= components_sources.flat_map do |source|
source.specs.map { |spec| Package.new(spec) }
@packages ||= specs.map do |spec|
Package.new(
name: spec.name,
path: spec.loaded_from,
dependencies: spec.dependencies.map(&:name) & root.dependencies
)
end
end

Expand All @@ -31,14 +35,18 @@ def lockfile
@lockfile ||= ::Bundler::LockfileParser.new(::Bundler.read_file(path))
end

def components_sources
@components_sources ||= @lockfile.sources.filter_map do |source|
def sources
@sources ||= lockfile.sources.filter_map do |source|
next unless source.path?

options = source.options.merge!("root_path" => @root)
::Bundler::Source::Path.new(options)
end
end

def specs
@specs ||= sources.flat_map { |source| source.specs.to_a }
end
end
end
end
5 changes: 2 additions & 3 deletions cobra_commander-ruby/lib/cobra_commander/ruby/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ module Ruby
class Package
attr_reader :path, :name, :dependencies

def initialize(spec = nil, path: spec&.loaded_from, name: spec&.name, dependencies: spec&.dependencies)
@spec = spec
def initialize(path:, dependencies:, name: nil)
@path = path
@name = name
@dependencies = dependencies&.map(&:name)
@dependencies = dependencies
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions cobra_commander-ruby/spec/cobra_commander/ruby/bundle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

RSpec.describe CobraCommander::Ruby::Bundle do
subject { CobraCommander::Ruby::Bundle.new(dummy_path) }
let(:hr_package) do
subject.packages.find do |package|
package.name.eql?("hr")
end
end

it "can load all the internal packages" do
expect(subject.packages.map(&:name)).to match_array %w[
authn
authz
finance
hr
sales
]
end

it "does not include external packages" do
expect(subject.packages.map(&:name)).to_not include "httparty"
end

it "loads the internal dependencies of loaded packages" do
expect(hr_package.dependencies).to match_array %w[authz authn finance]
end

it "package paths are the root path of a package" do
expect(hr_package.path).to eql "#{dummy_path}/components/hr/hr.gemspec"
end
end
4 changes: 0 additions & 4 deletions cobra_commander-ruby/spec/cobra_commander/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
it "has a version number" do
expect(CobraCommander::Ruby::VERSION).not_to be nil
end

it "does something useful" do
expect(false).to eq(true)
end
end
11 changes: 11 additions & 0 deletions cobra_commander-ruby/spec/dummy/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

path "components" do
gem "authn"
gem "authz"
gem "finance"
gem "hr"
gem "sales"
end

gem "httparty"
33 changes: 33 additions & 0 deletions cobra_commander-ruby/spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PATH
remote: components
specs:
authn (0.1.0)
authz (0.1.0)
authn
finance (0.1.0)
authn
authz
hr (0.1.0)
authn
authz
finance
sales (0.1.0)
authn
authz
hr

GEM
specs:

PLATFORMS
arm64-darwin-22

DEPENDENCIES
authn!
authz!
finance!
hr!
sales!

BUNDLED WITH
2.3.24
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "authn"
spec.version = "0.1.0"
spec.summary = "This is an example component for cobra_commander-ruby"
spec.authors = ["Carlos Palhares"]
end
10 changes: 10 additions & 0 deletions cobra_commander-ruby/spec/dummy/components/authz/authz.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "authz"
spec.version = "0.1.0"
spec.summary = "This is an example component for cobra_commander-ruby"
spec.authors = ["Carlos Palhares"]

spec.add_dependency "authn"
end
11 changes: 11 additions & 0 deletions cobra_commander-ruby/spec/dummy/components/finance/authz.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "finance"
spec.version = "0.1.0"
spec.summary = "This is an example component for cobra_commander-ruby"
spec.authors = ["Carlos Palhares"]

spec.add_dependency "authn"
spec.add_dependency "authz"
end
16 changes: 16 additions & 0 deletions cobra_commander-ruby/spec/dummy/components/hr/hr.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "hr"
spec.version = "0.1.0"
spec.summary = "This is an example component for cobra_commander-ruby"
spec.authors = ["Carlos Palhares"]

# External dependencies
spec.add_dependency "lockbox"

# Internal dependencies
spec.add_dependency "authn"
spec.add_dependency "authz"
spec.add_dependency "finance"
end
12 changes: 12 additions & 0 deletions cobra_commander-ruby/spec/dummy/components/sales/sales.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

Gem::Specification.new do |spec|
spec.name = "sales"
spec.version = "0.1.0"
spec.summary = "This is an example component for cobra_commander-ruby"
spec.authors = ["Carlos Palhares"]

spec.add_dependency "authn"
spec.add_dependency "authz"
spec.add_dependency "hr"
end
7 changes: 7 additions & 0 deletions cobra_commander-ruby/spec/dummy_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module DummyHelper
def dummy_path
File.join(__dir__, "dummy")
end
end
Loading

0 comments on commit 058a4bd

Please sign in to comment.