Skip to content

Commit

Permalink
Run bundle check || bundle install after hanami install (#128)
Browse files Browse the repository at this point in the history
* Run bundle check || bundle install after hanami install

To ensure any new Gemfile entries are installed

* Add test
  • Loading branch information
cllns authored Nov 7, 2023
1 parent 6a76576 commit 5df5d30
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/hanami/cli/commands/gem/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def call(app:, head: HEAD_DEFAULT, skip_install: SKIP_INSTALL_DEFAULT, skip_asse
end

out.puts "Running Hanami install..."
run_install_commmand!(head: head)
run_install_command!(head: head)
end
end
end
Expand All @@ -121,10 +121,14 @@ def call(app:, head: HEAD_DEFAULT, skip_install: SKIP_INSTALL_DEFAULT, skip_asse
attr_reader :generator
attr_reader :system_call

def run_install_commmand!(head:)
def run_install_command!(head:)
head_flag = head ? " --head" : ""
bundler.exec("hanami install#{head_flag}").tap do |result|
raise HanamiInstallError.new(result.err) unless result.successful?
if result.successful?
bundler.exec("check").successful? || bundler.exec("install")
else
raise HanamiInstallError.new(result.err)
end
end
end
end
Expand Down
51 changes: 51 additions & 0 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
.at_least(1)
.and_return(successful_system_call_result)

expect(bundler).to receive(:exec)
.with("check")
.at_least(1)
.and_return(successful_system_call_result)

app_name = "HanamiTeam"
app = "hanami_team"
subject.call(app: app_name)
Expand Down Expand Up @@ -55,6 +60,11 @@
.with("hanami install")
.and_return(successful_system_call_result)

expect(bundler).to receive(:exec)
.with("check")
.at_least(1)
.and_return(successful_system_call_result)

expect(system_call).to receive(:call).with("npm", ["install"])

subject.call(app: app, **kwargs)
Expand Down Expand Up @@ -428,6 +438,11 @@ module Types
.with("hanami install --head")
.and_return(successful_system_call_result)

expect(bundler).to receive(:exec)
.with("check")
.at_least(1)
.and_return(successful_system_call_result)

subject.call(app: app, **kwargs)

expect(fs.directory?(app)).to be(true)
Expand Down Expand Up @@ -483,6 +498,11 @@ module Types
.with("hanami install")
.and_return(successful_system_call_result)

expect(bundler).to receive(:exec)
.with("check")
.at_least(1)
.and_return(successful_system_call_result)

expect(system_call).not_to receive(:call).with("npm", ["install"])

subject.call(app: app, **kwargs)
Expand Down Expand Up @@ -535,6 +555,11 @@ module Types
.with("hanami install")
.and_return(successful_system_call_result)

expect(bundler).to receive(:exec)
.with("check")
.at_least(1)
.and_return(successful_system_call_result)

subject.call(app: app)

expect(fs.directory?(app)).to be(true)
Expand Down Expand Up @@ -569,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

0 comments on commit 5df5d30

Please sign in to comment.