Skip to content

Commit 3da3b44

Browse files
committed
First fix CI so it's green (see rails#780, rails#781)
fix options spec. allow line_editor spec to be run independently running `rspec spec/line_editor_spec.rb` generated a double error when it tries to re require "readline" fix expectations for ruby 3 treatment of hash arg try coveralls_reborn to fix ssl errors. Note that we could also use the coveralls action as recommended in https://github.com/tagliala/coveralls-ruby-reborn but it seems like a github token is needed, which makes it more complex for contributors This does mean dropping coveralls for EOLed rubies but do we really need to post to coveralls on each test run? Wouldn't one test run be enough?
1 parent ab3b5be commit 3da3b44

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99

1010
group :test do
1111
gem "childlabor"
12-
gem "coveralls", ">= 0.8.19"
12+
gem 'coveralls_reborn', '~> 0.23.1', require: false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
1313
gem "rspec", ">= 3.2"
1414
gem "rspec-mocks", ">= 3"
1515
gem "rubocop", "~> 0.50.0"

lib/thor/line_editor/readline.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
begin
2+
require "readline"
3+
rescue LoadError
4+
end
5+
16
class Thor
27
module LineEditor
38
class Readline < Basic
49
def self.available?
5-
begin
6-
require "readline"
7-
rescue LoadError
8-
end
9-
1010
Object.const_defined?(:Readline)
1111
end
1212

spec/helper.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
$TESTING = true
22

3-
require "simplecov"
4-
require "coveralls"
3+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
4+
require "simplecov"
5+
require "coveralls"
56

6-
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
7+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
78

8-
SimpleCov.start do
9-
add_filter "/spec"
10-
minimum_coverage(90)
9+
SimpleCov.start do
10+
add_filter "/spec"
11+
minimum_coverage(90)
12+
end
1113
end
1214

1315
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))

spec/line_editor_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
describe ".readline" do
1414
it "uses the Readline line editor" do
1515
editor = double("Readline")
16-
expect(Thor::LineEditor::Readline).to receive(:new).with("Enter your name ", :default => "Brian").and_return(editor)
16+
expect(Thor::LineEditor::Readline).to receive(:new).with("Enter your name ", {:default => "Brian"}).and_return(editor)
1717
expect(editor).to receive(:readline).and_return("George")
1818
expect(Thor::LineEditor.readline("Enter your name ", :default => "Brian")).to eq("George")
1919
end
@@ -35,7 +35,7 @@
3535
describe ".readline" do
3636
it "uses the Basic line editor" do
3737
editor = double("Basic")
38-
expect(Thor::LineEditor::Basic).to receive(:new).with("Enter your name ", :default => "Brian").and_return(editor)
38+
expect(Thor::LineEditor::Basic).to receive(:new).with("Enter your name ", {:default => "Brian"}).and_return(editor)
3939
expect(editor).to receive(:readline).and_return("George")
4040
expect(Thor::LineEditor.readline("Enter your name ", :default => "Brian")).to eq("George")
4141
end

spec/parser/options_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def remaining
116116
expected = "Unknown switches \"--baz\""
117117
expected << "\nDid you mean? \"--bar\"" if Thor::Correctable
118118

119-
expect { check_unknown! }.to raise_error(Thor::UnknownArgumentError, expected)
119+
expect { check_unknown! }.to raise_error(Thor::UnknownArgumentError) do |error|
120+
expect(error.to_s).to eq(expected)
121+
end
120122
end
121123

122124
it "skips leading non-switches" do

spec/shell/basic_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,80 +70,80 @@ def shell
7070

7171
it "prints a message to the user with the available options, expects case-sensitive matching, and determines the correctness of the answer" do
7272
flavors = %w(strawberry chocolate vanilla)
73-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("chocolate")
73+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', {:limited_to => flavors}).and_return("chocolate")
7474
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
7575
end
7676

7777
it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after an incorrect response" do
7878
flavors = %w(strawberry chocolate vanilla)
7979
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
80-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("moose tracks", "chocolate")
80+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', {:limited_to => flavors}).and_return("moose tracks", "chocolate")
8181
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
8282
end
8383

8484
it "prints a message to the user with the available options, expects case-sensitive matching, and reasks the question after a case-insensitive match" do
8585
flavors = %w(strawberry chocolate vanilla)
8686
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
87-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("cHoCoLaTe", "chocolate")
87+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', {:limited_to => flavors}).and_return("cHoCoLaTe", "chocolate")
8888
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate")
8989
end
9090

9191
it "prints a message to the user with the available options, expects case-insensitive matching, and determines the correctness of the answer" do
9292
flavors = %w(strawberry chocolate vanilla)
93-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors, :case_insensitive => true).and_return("CHOCOLATE")
93+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', {:limited_to => flavors, :case_insensitive => true}).and_return("CHOCOLATE")
9494
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors, :case_insensitive => true)).to eq("chocolate")
9595
end
9696

9797
it "prints a message to the user with the available options, expects case-insensitive matching, and reasks the question after an incorrect response" do
9898
flavors = %w(strawberry chocolate vanilla)
9999
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
100-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors, :case_insensitive => true).and_return("moose tracks", "chocolate")
100+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', {:limited_to => flavors, :case_insensitive => true}).and_return("moose tracks", "chocolate")
101101
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors, :case_insensitive => true)).to eq("chocolate")
102102
end
103103

104104
it "prints a message to the user containing a default and sets the default if only enter is pressed" do
105-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? (vanilla) ', :default => "vanilla").and_return("")
105+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? (vanilla) ', {:default => "vanilla"}).and_return("")
106106
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :default => "vanilla")).to eq("vanilla")
107107
end
108108

109109
it "prints a message to the user with the available options and reasks the question after an incorrect response and then returns the default" do
110110
flavors = %w(strawberry chocolate vanilla)
111111
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n")
112-
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ', :default => "vanilla", :limited_to => flavors).and_return("moose tracks", "")
112+
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] (vanilla) ', {:default => "vanilla", :limited_to => flavors}).and_return("moose tracks", "")
113113
expect(shell.ask("What's your favorite Neopolitan flavor?", :default => "vanilla", :limited_to => flavors)).to eq("vanilla")
114114
end
115115
end
116116

117117
describe "#yes?" do
118118
it "asks the user and returns true if the user replies yes" do
119-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("y")
119+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("y")
120120
expect(shell.yes?("Should I overwrite it?")).to be true
121121
end
122122

123123
it "asks the user and returns false if the user replies no" do
124-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("n")
124+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("n")
125125
expect(shell.yes?("Should I overwrite it?")).not_to be true
126126
end
127127

128128
it "asks the user and returns false if the user replies with an answer other than yes or no" do
129-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("foobar")
129+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("foobar")
130130
expect(shell.yes?("Should I overwrite it?")).to be false
131131
end
132132
end
133133

134134
describe "#no?" do
135135
it "asks the user and returns true if the user replies no" do
136-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("n")
136+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("n")
137137
expect(shell.no?("Should I overwrite it?")).to be true
138138
end
139139

140140
it "asks the user and returns false if the user replies yes" do
141-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("Yes")
141+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("Yes")
142142
expect(shell.no?("Should I overwrite it?")).to be false
143143
end
144144

145145
it "asks the user and returns false if the user replies with an answer other than yes or no" do
146-
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", :add_to_history => false).and_return("foobar")
146+
expect(Thor::LineEditor).to receive(:readline).with("Should I overwrite it? ", {:add_to_history => false}).and_return("foobar")
147147
expect(shell.no?("Should I overwrite it?")).to be false
148148
end
149149
end
@@ -431,13 +431,13 @@ def #456 Lanç...
431431
expect(content).to eq(<<-TABLE)
432432
Name Number Color
433433
Erik 1234567890123 green
434-
TABLE
434+
TABLE
435435
end
436436
end
437437

438438
describe "#file_collision" do
439439
it "shows a menu with options" do
440-
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', :add_to_history => false).and_return("n")
440+
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {:add_to_history => false}).and_return("n")
441441
shell.file_collision("foo")
442442
end
443443

@@ -478,7 +478,7 @@ def #456 Lanç...
478478
end
479479

480480
it "always returns true if the user chooses always" do
481-
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', :add_to_history => false).and_return("a")
481+
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqh] ', {:add_to_history => false}).and_return("a")
482482

483483
expect(shell.file_collision("foo")).to be true
484484

@@ -488,7 +488,7 @@ def #456 Lanç...
488488

489489
describe "when a block is given" do
490490
it "displays diff and merge options to the user" do
491-
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqdhm] ', :add_to_history => false).and_return("s")
491+
expect(Thor::LineEditor).to receive(:readline).with('Overwrite foo? (enter "h" for help) [Ynaqdhm] ', {:add_to_history => false}).and_return("s")
492492
shell.file_collision("foo") {}
493493
end
494494

0 commit comments

Comments
 (0)