Skip to content

Commit b9d0585

Browse files
committed
Only set non-nil Readline.completion_proc.
This fixes an ArgumentError when running with Ruby 1.8.7.
1 parent 577fcc4 commit b9d0585

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/thor/line_editor/readline.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def self.available?
1313
def readline
1414
if echo?
1515
::Readline.completion_append_character = nil
16-
::Readline.completion_proc = completion_proc
16+
# Ruby 1.8.7 does not allow Readline.completion_proc= to receive nil.
17+
if complete = completion_proc
18+
::Readline.completion_proc = complete
19+
end
1720
::Readline.readline(prompt, add_to_history?)
1821
else
1922
super

spec/line_editor/readline_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
describe '#readline' do
2424
it 'invokes the readline library' do
2525
expect(::Readline).to receive(:readline).with('> ', true).and_return('foo')
26-
expect(::Readline).to receive(:completion_proc=).with(nil)
26+
expect(::Readline).not_to receive(:completion_proc=)
2727
editor = Thor::LineEditor::Readline.new('> ', {})
2828
expect(editor.readline).to eq('foo')
2929
end
3030

3131
it 'supports the add_to_history option' do
3232
expect(::Readline).to receive(:readline).with('> ', false).and_return('foo')
33-
expect(::Readline).to receive(:completion_proc=).with(nil)
33+
expect(::Readline).not_to receive(:completion_proc=)
3434
editor = Thor::LineEditor::Readline.new('> ', :add_to_history => false)
3535
expect(editor.readline).to eq('foo')
3636
end

0 commit comments

Comments
 (0)