Skip to content

Commit

Permalink
Only set non-nil Readline.completion_proc.
Browse files Browse the repository at this point in the history
This fixes an ArgumentError when running with Ruby 1.8.7.
  • Loading branch information
TimMoore committed Dec 23, 2013
1 parent 577fcc4 commit b9d0585
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/thor/line_editor/readline.rb
Expand Up @@ -13,7 +13,10 @@ def self.available?
def readline
if echo?
::Readline.completion_append_character = nil
::Readline.completion_proc = completion_proc
# Ruby 1.8.7 does not allow Readline.completion_proc= to receive nil.
if complete = completion_proc
::Readline.completion_proc = complete
end
::Readline.readline(prompt, add_to_history?)
else
super
Expand Down
4 changes: 2 additions & 2 deletions spec/line_editor/readline_spec.rb
Expand Up @@ -23,14 +23,14 @@
describe '#readline' do
it 'invokes the readline library' do
expect(::Readline).to receive(:readline).with('> ', true).and_return('foo')
expect(::Readline).to receive(:completion_proc=).with(nil)
expect(::Readline).not_to receive(:completion_proc=)
editor = Thor::LineEditor::Readline.new('> ', {})
expect(editor.readline).to eq('foo')
end

it 'supports the add_to_history option' do
expect(::Readline).to receive(:readline).with('> ', false).and_return('foo')
expect(::Readline).to receive(:completion_proc=).with(nil)
expect(::Readline).not_to receive(:completion_proc=)
editor = Thor::LineEditor::Readline.new('> ', :add_to_history => false)
expect(editor.readline).to eq('foo')
end
Expand Down

0 comments on commit b9d0585

Please sign in to comment.