From 048eeb7676a4e47aadeb810cd192d6d167592171 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Mon, 6 Nov 2023 21:31:25 -0700 Subject: [PATCH] Add test --- lib/hanami/cli/commands/gem/new.rb | 2 +- spec/unit/hanami/cli/commands/gem/new_spec.rb | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/hanami/cli/commands/gem/new.rb b/lib/hanami/cli/commands/gem/new.rb index 8928460d..78255ba8 100644 --- a/lib/hanami/cli/commands/gem/new.rb +++ b/lib/hanami/cli/commands/gem/new.rb @@ -120,7 +120,7 @@ def run_install_command!(head:) head_flag = head ? " --head" : "" bundler.exec("hanami install#{head_flag}").tap do |result| if result.successful? - bundler.exec("check").successful? || bundle.exec("install") + bundler.exec("check").successful? || bundler.exec("install") else raise HanamiInstallError.new(result.err) end diff --git a/spec/unit/hanami/cli/commands/gem/new_spec.rb b/spec/unit/hanami/cli/commands/gem/new_spec.rb index 49ee3ce1..d1f5bda7 100644 --- a/spec/unit/hanami/cli/commands/gem/new_spec.rb +++ b/spec/unit/hanami/cli/commands/gem/new_spec.rb @@ -594,4 +594,30 @@ class App < Hanami::App expect { subject.call(app: app) }.to raise_error(Hanami::CLI::PathAlreadyExistsError) end + + it "calls bundle install if bundle check fails" do + expect(bundler).to receive(:install!) + .at_least(1) + .and_return(true) + + expect(bundler).to receive(:exec) + .with("hanami install") + .at_least(1) + .and_return(successful_system_call_result) + + expect(bundler).to receive(:exec) + .with("check") + .at_least(1) + .and_return( + instance_double(Hanami::CLI::SystemCall::Result, successful?: false) + ) + + expect(bundler).to receive(:exec) + .with("install") + .once + .and_return(successful_system_call_result) + + app_name = "no_gems_installed" + subject.call(app: app_name) + end end