Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run bundle check || bundle install after hanami install #128

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -103,7 +103,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 @@ -116,10 +116,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