Skip to content

Commit

Permalink
(PDK-806) Update metadata interview text if metadata.json already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Feb 15, 2018
1 parent c6db211 commit b8ad6e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/pdk/generate/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,17 @@ def self.module_interview(metadata, opts = {})

interview.add_questions(questions)

action = File.file?('metadata.json') ? _('update') : _('create')
puts _(
"\nWe need to create a metadata.json file for this module, so we\'re going to ask you %{count} " \
"\nWe need to %{action} the metadata.json file for this module, so we\'re going to ask you %{count} " \
"questions.\n" \
'If the question is not applicable to this module, accept the default option ' \
'shown after each question. You can modify any answers at any time by manually updating ' \
"the metadata.json file.\n\n",
) % { count: interview.num_questions }
) % {
count: interview.num_questions,
action: action,
}

answers = interview.run

Expand Down
12 changes: 10 additions & 2 deletions spec/unit/pdk/generate/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,12 @@
]
end

before(:each) do
allow(File).to receive(:file?).with('metadata.json').and_return(true)
end

it 'populates the metadata object based on user input' do
allow($stdout).to receive(:puts).with(a_string_matching(%r{1 question}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{update the metadata\.json.+1 question}m))

expected_metadata = PDK::Module::Metadata.new.update!(default_metadata).data.dup
expected_metadata['source'] = 'https://something'
Expand Down Expand Up @@ -323,8 +327,12 @@
]
end

before(:each) do
allow(File).to receive(:file?).with('metadata.json').and_return(false)
end

it 'populates the Metadata object based on user input' do
allow($stdout).to receive(:puts).with(a_string_matching(%r{9 questions}m))
allow($stdout).to receive(:puts).with(a_string_matching(%r{create the metadata\.json.+9 questions}m))

expect(interview_metadata).to include(
'name' => 'foo-bar',
Expand Down

0 comments on commit b8ad6e5

Please sign in to comment.