Skip to content

Commit

Permalink
Run bundle check || bundle install after hanami install
Browse files Browse the repository at this point in the history
To ensure any new Gemfile entries are installed
  • Loading branch information
cllns committed Nov 7, 2023
1 parent 6f91d15 commit 3c555c3
Show file tree
Hide file tree
Showing 2 changed files with 32 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 @@ -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? || bundle.exec("install")
else
raise HanamiInstallError.new(result.err)
end
end
end
end
Expand Down
25 changes: 25 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

0 comments on commit 3c555c3

Please sign in to comment.