Skip to content

Commit b3d47de

Browse files
committed
Fix Readline.readline use
1 parent 885cbbf commit b3d47de

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

app/controllers/core.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def update_db_required?
3737
return false unless user_interaction? && local_db.outdated?
3838

3939
output('@notice', msg: 'It seems like you have not updated the database for some time.')
40-
print '[?] Do you want to update now? [Y]es [N]o, default: [N]'
40+
response = Readline.readline('[?] Do you want to update now? [Y]es [N]o, default: [N] ', true)
4141

42-
/^y/i.match?(Readline.readline)
42+
!!/^y/i.match?(response)
4343
end
4444

4545
def update_db

spec/app/controllers/core_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,25 @@
106106

107107
context 'when the db is outdated' do
108108
before do
109+
allow(core).to receive(:user_interaction?).and_return(true)
109110
expect(core.local_db).to receive(:outdated?).ordered.and_return(true)
110111
expect(core.formatter).to receive(:output).with('@notice', hash_including(:msg), 'core').ordered
111-
expect($stdout).to receive(:write).ordered # for the print()
112112
end
113113

114114
context 'when a positive answer' do
115-
before { expect(Readline).to receive(:readline).and_return('Yes').ordered }
115+
before do
116+
expect(Readline).to receive(:readline).with('[?] Do you want to update now? [Y]es [N]o, default: [N] ',
117+
true).and_return('Yes')
118+
end
116119

117120
its(:update_db_required?) { should eql true }
118121
end
119122

120123
context 'when a negative answer' do
121-
before { expect(Readline).to receive(:readline).and_return('no').ordered }
124+
before do
125+
expect(Readline).to receive(:readline).with('[?] Do you want to update now? [Y]es [N]o, default: [N] ',
126+
true).and_return('No')
127+
end
122128

123129
its(:update_db_required?) { should eql false }
124130
end

0 commit comments

Comments
 (0)