Skip to content

Commit 4518ec4

Browse files
Merge pull request rails#46478 from jonathanhefner/app_generator_test-run_generator_and_bundler
Add Bundler helper for `AppGeneratorTest`
2 parents 2d2fdc9 + c63a13f commit 4518ec4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

railties/test/generators/app_generator_test.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def test_no_skip_javascript_option_with_no_skip_javascript_argument
825825
end
826826

827827
def test_hotwire
828-
run_generator [destination_root, "--no-skip-bundle"]
828+
run_generator_and_bundler [destination_root]
829829
assert_gem "turbo-rails"
830830
assert_gem "stimulus-rails"
831831
assert_file "app/views/layouts/application.html.erb" do |content|
@@ -848,15 +848,15 @@ def test_skip_hotwire
848848
end
849849

850850
def test_css_option_with_asset_pipeline_tailwind
851-
run_generator [destination_root, "--css", "tailwind", "--no-skip-bundle"]
851+
run_generator_and_bundler [destination_root, "--css=tailwind"]
852852
assert_gem "tailwindcss-rails"
853853
assert_file "app/views/layouts/application.html.erb" do |content|
854854
assert_match(/tailwind/, content)
855855
end
856856
end
857857

858858
def test_css_option_with_cssbundling_gem
859-
run_generator [destination_root, "--css", "postcss", "--no-skip-bundle"]
859+
run_generator_and_bundler [destination_root, "--css=postcss"]
860860
assert_gem "cssbundling-rails"
861861
assert_file "app/assets/stylesheets/application.postcss.css"
862862
end
@@ -1068,6 +1068,20 @@ def test_name_option
10681068
end
10691069

10701070
private
1071+
def run_generator_and_bundler(args)
1072+
option_args, positional_args = args.partition { |arg| arg.start_with?("--") }
1073+
option_args << "--no-skip-bundle"
1074+
generator(positional_args, option_args)
1075+
1076+
# Stub `rails_gemfile_entry` so that Bundler resolves `gem "rails"` to the
1077+
# current repository instead of searching for an invalid version number
1078+
# (for a version that hasn't been released yet).
1079+
rails_gemfile_entry = Rails::Generators::AppBase::GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
1080+
generator.stub(:rails_gemfile_entry, -> { rails_gemfile_entry }) do
1081+
quietly { run_generator_instance }
1082+
end
1083+
end
1084+
10711085
def run_app_update(app_root = destination_root)
10721086
Dir.chdir(app_root) do
10731087
gemfile_contents = File.read("Gemfile")

0 commit comments

Comments
 (0)