Skip to content

Commit ab74cfd

Browse files
committed
Fix readline specs
An error was introduced in commit 7061b06 where readline specs fail because `require "readline"` is be called after the spec has established a mock `::Readline`. Prior to that change `require "readline"` was always only called once. This patch: * memoizes the `require` to ensure that it only happens once * leaves the `Object.const_defined?` check in place to keep tests simple * eagerly calls `available?` in the readline spec to match the original author's intent by requiring `readline` before the specs start.
1 parent 2cc6701 commit ab74cfd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/thor/line_editor/readline.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class Thor
22
module LineEditor
33
class Readline < Basic
44
def self.available?
5-
begin
6-
require "readline"
5+
@readline_reqd ||= begin
6+
require "readline"
77
rescue LoadError
88
end
99

spec/line_editor/readline_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
describe Thor::LineEditor::Readline do
44
before do
5+
# Eagerly check Readline availability and cache for this spec
6+
Thor::LineEditor::Readline.available?
57
unless defined? ::Readline
68
::Readline = double("Readline")
79
allow(::Readline).to receive(:completion_append_character=).with(nil)

0 commit comments

Comments
 (0)