Skip to content

Commit

Permalink
Add integration test for --commit feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Sep 19, 2024
1 parent 76f4aae commit ee03852
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
bundler: latest
- run: git config --global user.name 'github-actions[bot]'
- run: git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- run: bundle exec rake test
40 changes: 23 additions & 17 deletions test/integration/cli_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
module BundleUpdateInteractive
class CLIIntegrationIest < Minitest::Test
def test_updates_lock_file_based_on_selected_gem_while_honoring_gemfile_requirement
out, _gemfile, lockfile = run_bundle_update_interactive(
fixture: "integration",
argv: [],
key_presses: "j \n"
)
out, _gemfile, lockfile = within_fixture_copy("integration") do
run_bundle_update_interactive(argv: [], key_presses: "j \n")
end

assert_includes out, "Color legend:"

Expand Down Expand Up @@ -45,11 +43,9 @@ def test_updates_lock_file_based_on_selected_gem_while_honoring_gemfile_requirem
def test_updates_lock_file_and_gemfile_to_accommodate_latest_version_when_latest_option_is_specified
latest_minitest_version = fetch_latest_gem_version_from_rubygems_api("minitest")

out, gemfile, lockfile = run_bundle_update_interactive(
fixture: "integration",
argv: ["--latest"],
key_presses: "j \n"
)
out, gemfile, lockfile = within_fixture_copy("integration") do
run_bundle_update_interactive(argv: ["--latest"], key_presses: "j \n")
end

assert_includes out, "Color legend:"

Expand Down Expand Up @@ -84,9 +80,21 @@ def test_updates_lock_file_and_gemfile_to_accommodate_latest_version_when_latest
LOCK
end

def test_updates_each_selected_gem_with_a_git_commit
out, _gemfile, _lockfile = within_fixture_copy("integration") do
system "git init", out: File::NULL, exception: true
system "git add .", out: File::NULL, exception: true
system "git commit -m init", out: File::NULL, exception: true
run_bundle_update_interactive(argv: ["--commit"], key_presses: " j \n")
end

assert_match(/^\[main \h+\] Update bigdecimal 3\.1\.7 →/, out)
assert_match(/^\[main \h+\] Update minitest 5\.0\.0 →/, out)
end

private

def run_bundle_update_interactive(fixture:, argv:, key_presses: "\n")
def run_bundle_update_interactive(argv:, key_presses: "\n")
command = [
{ "GEM_HOME" => ENV.fetch("GEM_HOME", nil) },
Gem.ruby,
Expand All @@ -95,13 +103,11 @@ def run_bundle_update_interactive(fixture:, argv:, key_presses: "\n")
File.expand_path("../../exe/bundler-update-interactive", __dir__),
*argv
]
within_fixture_copy(fixture) do
Bundler.with_unbundled_env do
out, err, status = Open3.capture3(*command, stdin_data: key_presses)
raise "Command failed: #{[out, err].join}" unless status.success?
Bundler.with_unbundled_env do
out, err, status = Open3.capture3(*command, stdin_data: key_presses)
raise "Command failed: #{[out, err].join}" unless status.success?

[out, File.read("Gemfile"), File.read("Gemfile.lock")]
end
[out, File.read("Gemfile"), File.read("Gemfile.lock")]
end
end

Expand Down

0 comments on commit ee03852

Please sign in to comment.