Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions lib/thor/line_editor/readline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Thor
module LineEditor
class Readline < Basic
def self.available?
begin
require "readline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require by default only happens once. Why do we need this memoization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had myself convinced that subsequent calls after building the mock would raise a TypeError here, but I was incorrect. Will update this PR.

@readline_reqd ||= begin
require "readline"
rescue LoadError
end

Expand Down
2 changes: 2 additions & 0 deletions spec/line_editor/readline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

describe Thor::LineEditor::Readline do
before do
# Eagerly check Readline availability and cache for this spec
Thor::LineEditor::Readline.available?
unless defined? ::Readline
::Readline = double("Readline")
allow(::Readline).to receive(:completion_append_character=).with(nil)
Expand Down