From be619092787cb9e45719a490d9d73caf2cfc88f3 Mon Sep 17 00:00:00 2001 From: Alex Evanczuk Date: Fri, 6 Jan 2023 07:28:32 -0500 Subject: [PATCH] Skip gems when adding load paths (#50) --- lib/stimpack/integrations/factory_bot.rb | 3 +-- lib/stimpack/integrations/rails.rb | 4 ++-- lib/stimpack/version.rb | 2 +- sorbet/rbi/gems/{packs@0.0.4.rbi => packs@0.0.6.rbi} | 3 +++ .../components/jackets/app/views/show.html.erb | 0 .../rails-7.0/components/jackets/jackets.gemspec | 0 spec/fixtures/rails-7.0/components/jackets/package.yml | 0 spec/spec_helper.rb | 7 +++++++ spec/stimpack_spec.rb | 10 +++++++--- 9 files changed, 21 insertions(+), 8 deletions(-) rename sorbet/rbi/gems/{packs@0.0.4.rbi => packs@0.0.6.rbi} (97%) create mode 100644 spec/fixtures/rails-7.0/components/jackets/app/views/show.html.erb create mode 100644 spec/fixtures/rails-7.0/components/jackets/jackets.gemspec create mode 100644 spec/fixtures/rails-7.0/components/jackets/package.yml diff --git a/lib/stimpack/integrations/factory_bot.rb b/lib/stimpack/integrations/factory_bot.rb index 9836f61..088e5dd 100644 --- a/lib/stimpack/integrations/factory_bot.rb +++ b/lib/stimpack/integrations/factory_bot.rb @@ -7,8 +7,7 @@ def initialize(app) return unless app.config.respond_to?(:factory_bot) Stimpack.configure_packs - Packs.all.each do |pack| - next if pack.relative_path.glob('*.gemspec').any? + Packs.all.reject(&:is_gem?).each do |pack| app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s end end diff --git a/lib/stimpack/integrations/rails.rb b/lib/stimpack/integrations/rails.rb index 5de8e9b..d03aabc 100644 --- a/lib/stimpack/integrations/rails.rb +++ b/lib/stimpack/integrations/rails.rb @@ -17,7 +17,7 @@ def initialize(app) end def create_engines - Packs.all.each do |pack| + Packs.all.reject(&:is_gem?).each do |pack| next unless pack.metadata['engine'] create_engine(pack) @@ -25,7 +25,7 @@ def create_engines end def inject_paths - Packs.all.each do |pack| + Packs.all.reject(&:is_gem?).each do |pack| Stimpack.config.paths.each do |path| @app.paths[path] << pack.relative_path.join(path) end diff --git a/lib/stimpack/version.rb b/lib/stimpack/version.rb index 33bba13..6397e77 100644 --- a/lib/stimpack/version.rb +++ b/lib/stimpack/version.rb @@ -1,3 +1,3 @@ module Stimpack - VERSION = "0.8.2".freeze + VERSION = "0.8.3".freeze end diff --git a/sorbet/rbi/gems/packs@0.0.4.rbi b/sorbet/rbi/gems/packs@0.0.6.rbi similarity index 97% rename from sorbet/rbi/gems/packs@0.0.4.rbi rename to sorbet/rbi/gems/packs@0.0.6.rbi index 1fceaca..f45ef34 100644 --- a/sorbet/rbi/gems/packs@0.0.4.rbi +++ b/sorbet/rbi/gems/packs@0.0.6.rbi @@ -42,6 +42,9 @@ class Packs::Pack < ::T::Struct const :raw_hash, T::Hash[T.untyped, T.untyped] const :relative_path, ::Pathname + sig { returns(T::Boolean) } + def is_gem?; end + sig { returns(::String) } def last_name; end diff --git a/spec/fixtures/rails-7.0/components/jackets/app/views/show.html.erb b/spec/fixtures/rails-7.0/components/jackets/app/views/show.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/rails-7.0/components/jackets/jackets.gemspec b/spec/fixtures/rails-7.0/components/jackets/jackets.gemspec new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/rails-7.0/components/jackets/package.yml b/spec/fixtures/rails-7.0/components/jackets/package.yml new file mode 100644 index 0000000..e69de29 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ca5f4c8..52240dd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,3 +12,10 @@ c.syntax = :expect end end + +def require_test_rails_application + rails_dir = Pathname.new(File.expand_path("fixtures/rails-7.0", __dir__)) + Dir.chdir(rails_dir) + require_relative rails_dir.join("config/environment") + rails_dir +end diff --git a/spec/stimpack_spec.rb b/spec/stimpack_spec.rb index 20944d5..13aa07d 100644 --- a/spec/stimpack_spec.rb +++ b/spec/stimpack_spec.rb @@ -1,8 +1,6 @@ require "pathname" -rails_dir = Pathname.new(File.expand_path("fixtures/rails-7.0", __dir__)) -Dir.chdir(rails_dir) -require_relative rails_dir.join("config/environment") +rails_dir = require_test_rails_application RSpec.describe Stimpack do it "autoloads classes in autoload paths" do @@ -15,6 +13,12 @@ end end + it "does not add gem paths to the application" do + Stimpack.config.paths.each do |path| + expect(Rails.application.paths[path].paths).to_not include(rails_dir.join('components', "jackets", path)) + end + end + it "creates engines namespace for engine packs" do expect(defined?(Shoes::Engine)).to eq("constant") end