generated from mattbrictson/gem
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a true integration test that actually executes Bundler (#41)
Before, our CLI tests were doing a significant amount of stubbing to avoid making external calls to Bundler commands. This limited the value of these tests. It also made them tedious to write, and required behind-the-scenes knowledge of when and how the lower-level code called out to Bundler. In this PR, I refactored the existing CLI tests so that the stubbing is done at a higher level: at the `Reporter` API. This makes test setup easier while still allowing us to write tests to cover various CLI edge cases, like error handing. For the primary, "happy path" case, I've created a `CLIIntegrationTest`. This runs the actual `update-interactive` executable via `Open3.capture3`, so every layer of the code base is exercised. Most importantly, Bundler commands themselves are actually executed. The integration test confirms that when a gem is selected to be updated, the update really happens. It does this by inspecting the `Gemfile.lock` to see that the gem version was changed as expected. I also updated the `mocha` configuration to make stubbing more strict going forward.
- Loading branch information
1 parent
72075a3
commit 76a584f
Showing
7 changed files
with
128 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
gem "bigdecimal" | ||
gem "minitest", "~> 5.0.0" | ||
gem "rake" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
bigdecimal (3.1.7) | ||
minitest (5.0.0) | ||
rake (12.3.3) | ||
|
||
PLATFORMS | ||
arm64-darwin-23 | ||
ruby | ||
|
||
DEPENDENCIES | ||
bigdecimal | ||
minitest (~> 5.0.0) | ||
rake | ||
|
||
BUNDLED WITH | ||
2.5.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "open3" | ||
require "tmpdir" | ||
|
||
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" | ||
) | ||
|
||
assert_includes out, "Color legend:" | ||
|
||
assert_includes out, "3 gems can be updated." | ||
assert_includes out, "‣ ⬡ bigdecimal 3.1.7 →" | ||
assert_includes out, " ⬡ minitest 5.0.0 → 5.0.8" | ||
assert_includes out, " ⬡ rake 12.3.3 →" | ||
|
||
assert_includes out, "‣ ⬢ minitest 5.0.0 → 5.0.8" | ||
|
||
assert_includes out, "Updating the following gems." | ||
assert_includes out, "minitest 5.0.0 → 5.0.8 :default" | ||
|
||
assert_includes out, "Bundle updated!" | ||
|
||
assert_includes lockfile, <<~LOCK | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
bigdecimal (3.1.7) | ||
minitest (5.0.8) | ||
LOCK | ||
assert_includes lockfile, <<~LOCK | ||
DEPENDENCIES | ||
bigdecimal | ||
minitest (~> 5.0.0) | ||
LOCK | ||
end | ||
|
||
private | ||
|
||
def run_bundle_update_interactive(fixture:, argv:, key_presses: "\n") | ||
command = [ | ||
{ "GEM_HOME" => ENV.fetch("GEM_HOME", nil) }, | ||
Gem.ruby, | ||
"-I", | ||
File.expand_path("../../lib", __dir__), | ||
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? | ||
|
||
[out, File.read("Gemfile"), File.read("Gemfile.lock")] | ||
end | ||
end | ||
end | ||
|
||
def within_fixture_copy(fixture, &block) | ||
fixture_path = File.join(File.expand_path("../fixtures", __dir__), fixture) | ||
Dir.mktmpdir do |tmp| | ||
FileUtils.cp_r(fixture_path, tmp) | ||
Dir.chdir(File.join(tmp, File.basename(fixture_path)), &block) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require "mocha/minitest" | ||
|
||
Mocha.configure do |config| | ||
config.stubbing_method_on_nil = :prevent | ||
config.stubbing_non_existent_method = :prevent | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters