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

(PDK-1527) Handle pdk new module --skip-interview without module name #788

Merged
merged 1 commit into from
Oct 23, 2019
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
9 changes: 8 additions & 1 deletion lib/pdk/cli/new/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ module PDK::CLI
opts[:'full-interview'] = false
end

unless module_name.nil? || module_name.empty?
if module_name.nil? || module_name.empty?
if opts[:'skip-interview']
raise PDK::CLI::ExitWithError, _(
'You must specify a module name on the command line when running ' \
'with --skip-interview.',
)
end
else
module_name_parts = module_name.split('-', 2)
if module_name_parts.size > 1
opts[:username] = module_name_parts[0]
Expand Down
49 changes: 35 additions & 14 deletions spec/unit/pdk/cli/new/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,43 @@
subject { PDK::CLI.instance_variable_get(:@new_module_cmd) }

context 'when not passed a module name' do
it 'continues to module interview' do
expect(PDK::Generate::Module).to receive(:invoke)
expect(logger).to receive(:info).with(%r{Creating new module:})
PDK::CLI.run(%w[new module])
context 'and run without --skip-interview' do
it 'continues to module interview' do
expect(PDK::Generate::Module).to receive(:invoke)
expect(logger).to receive(:info).with(%r{Creating new module:})
PDK::CLI.run(%w[new module])
end

it 'submits the command to analytics' do
allow(PDK::Generate::Module).to receive(:invoke)

expect(analytics).to receive(:screen_view).with(
'new_module',
output_format: 'default',
ruby_version: RUBY_VERSION,
)

PDK::CLI.run(%w[new module])
end
end

it 'submits the command to analytics' do
allow(PDK::Generate::Module).to receive(:invoke)
context 'and run with --skip-interview' do
it 'exits with an error' do
expect(logger).to receive(:error).with(%r{must specify a module name}i)

expect(analytics).to receive(:screen_view).with(
'new_module',
output_format: 'default',
ruby_version: RUBY_VERSION,
)
expect { PDK::CLI.run(%w[new module --skip-interview]) }.to exit_nonzero
end

PDK::CLI.run(%w[new module])
it 'submits the command to analytics' do
expect(analytics).to receive(:screen_view).with(
'new_module',
cli_options: 'skip-interview=true',
output_format: 'default',
ruby_version: RUBY_VERSION,
)

expect { PDK::CLI.run(%w[new module --skip-interview]) }.to exit_nonzero
end
end
end

Expand Down Expand Up @@ -197,7 +218,7 @@
expect(logger).to receive(:info).with(a_string_matching(%r{Ignoring --full-interview and continuing with --skip-interview.}i))
expect(PDK::Generate::Module).to receive(:invoke).with(hash_including(:'skip-interview' => true, :'full-interview' => false))

PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview'])
PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview', module_name])
end

it 'submits the command to analytics' do
Expand All @@ -210,7 +231,7 @@
ruby_version: RUBY_VERSION,
)

PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview'])
PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview', module_name])
end
end
end
Expand Down