Skip to content

Commit

Permalink
Merge pull request #46478 from jonathanhefner/app_generator_test-run_…
Browse files Browse the repository at this point in the history
…generator_and_bundler

Add Bundler helper for `AppGeneratorTest`
  • Loading branch information
jonathanhefner committed Nov 15, 2022
2 parents 2d2fdc9 + c63a13f commit 4518ec4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -825,7 +825,7 @@ def test_no_skip_javascript_option_with_no_skip_javascript_argument
end

def test_hotwire
run_generator [destination_root, "--no-skip-bundle"]
run_generator_and_bundler [destination_root]
assert_gem "turbo-rails"
assert_gem "stimulus-rails"
assert_file "app/views/layouts/application.html.erb" do |content|
Expand All @@ -848,15 +848,15 @@ def test_skip_hotwire
end

def test_css_option_with_asset_pipeline_tailwind
run_generator [destination_root, "--css", "tailwind", "--no-skip-bundle"]
run_generator_and_bundler [destination_root, "--css=tailwind"]
assert_gem "tailwindcss-rails"
assert_file "app/views/layouts/application.html.erb" do |content|
assert_match(/tailwind/, content)
end
end

def test_css_option_with_cssbundling_gem
run_generator [destination_root, "--css", "postcss", "--no-skip-bundle"]
run_generator_and_bundler [destination_root, "--css=postcss"]
assert_gem "cssbundling-rails"
assert_file "app/assets/stylesheets/application.postcss.css"
end
Expand Down Expand Up @@ -1068,6 +1068,20 @@ def test_name_option
end

private
def run_generator_and_bundler(args)
option_args, positional_args = args.partition { |arg| arg.start_with?("--") }
option_args << "--no-skip-bundle"
generator(positional_args, option_args)

# Stub `rails_gemfile_entry` so that Bundler resolves `gem "rails"` to the
# current repository instead of searching for an invalid version number
# (for a version that hasn't been released yet).
rails_gemfile_entry = Rails::Generators::AppBase::GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
generator.stub(:rails_gemfile_entry, -> { rails_gemfile_entry }) do
quietly { run_generator_instance }
end
end

def run_app_update(app_root = destination_root)
Dir.chdir(app_root) do
gemfile_contents = File.read("Gemfile")
Expand Down

0 comments on commit 4518ec4

Please sign in to comment.