thor 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +13 -7
  3. data/Thorfile +4 -5
  4. data/bin/thor +1 -1
  5. data/lib/thor.rb +78 -67
  6. data/lib/thor/actions.rb +57 -56
  7. data/lib/thor/actions/create_file.rb +33 -35
  8. data/lib/thor/actions/create_link.rb +2 -3
  9. data/lib/thor/actions/directory.rb +37 -38
  10. data/lib/thor/actions/empty_directory.rb +67 -69
  11. data/lib/thor/actions/file_manipulation.rb +17 -15
  12. data/lib/thor/actions/inject_into_file.rb +27 -29
  13. data/lib/thor/base.rb +193 -189
  14. data/lib/thor/command.rb +20 -23
  15. data/lib/thor/core_ext/hash_with_indifferent_access.rb +21 -24
  16. data/lib/thor/core_ext/io_binary_read.rb +2 -4
  17. data/lib/thor/core_ext/ordered_hash.rb +9 -11
  18. data/lib/thor/error.rb +5 -1
  19. data/lib/thor/group.rb +53 -54
  20. data/lib/thor/invocation.rb +44 -38
  21. data/lib/thor/line_editor.rb +17 -0
  22. data/lib/thor/line_editor/basic.rb +35 -0
  23. data/lib/thor/line_editor/readline.rb +88 -0
  24. data/lib/thor/parser.rb +4 -4
  25. data/lib/thor/parser/argument.rb +28 -29
  26. data/lib/thor/parser/arguments.rb +102 -98
  27. data/lib/thor/parser/option.rb +26 -22
  28. data/lib/thor/parser/options.rb +86 -86
  29. data/lib/thor/rake_compat.rb +9 -10
  30. data/lib/thor/runner.rb +141 -141
  31. data/lib/thor/shell.rb +27 -34
  32. data/lib/thor/shell/basic.rb +91 -63
  33. data/lib/thor/shell/color.rb +44 -43
  34. data/lib/thor/shell/html.rb +59 -60
  35. data/lib/thor/util.rb +24 -27
  36. data/lib/thor/version.rb +1 -1
  37. data/spec/actions/create_file_spec.rb +25 -27
  38. data/spec/actions/create_link_spec.rb +19 -18
  39. data/spec/actions/directory_spec.rb +31 -31
  40. data/spec/actions/empty_directory_spec.rb +18 -18
  41. data/spec/actions/file_manipulation_spec.rb +38 -28
  42. data/spec/actions/inject_into_file_spec.rb +13 -13
  43. data/spec/actions_spec.rb +43 -43
  44. data/spec/base_spec.rb +45 -38
  45. data/spec/command_spec.rb +13 -14
  46. data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -19
  47. data/spec/core_ext/ordered_hash_spec.rb +6 -6
  48. data/spec/exit_condition_spec.rb +4 -4
  49. data/spec/fixtures/invoke.thor +19 -0
  50. data/spec/fixtures/script.thor +1 -1
  51. data/spec/group_spec.rb +30 -24
  52. data/spec/helper.rb +28 -15
  53. data/spec/invocation_spec.rb +39 -19
  54. data/spec/line_editor/basic_spec.rb +28 -0
  55. data/spec/line_editor/readline_spec.rb +69 -0
  56. data/spec/line_editor_spec.rb +43 -0
  57. data/spec/parser/argument_spec.rb +12 -12
  58. data/spec/parser/arguments_spec.rb +11 -11
  59. data/spec/parser/option_spec.rb +33 -25
  60. data/spec/parser/options_spec.rb +66 -52
  61. data/spec/quality_spec.rb +75 -0
  62. data/spec/rake_compat_spec.rb +10 -10
  63. data/spec/register_spec.rb +60 -30
  64. data/spec/runner_spec.rb +67 -62
  65. data/spec/sandbox/application.rb +2 -0
  66. data/spec/sandbox/app{1}/README +3 -0
  67. data/spec/sandbox/bundle/execute.rb +6 -0
  68. data/spec/sandbox/bundle/main.thor +1 -0
  69. data/spec/sandbox/command.thor +10 -0
  70. data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
  71. data/spec/sandbox/doc/COMMENTER +11 -0
  72. data/spec/sandbox/doc/README +3 -0
  73. data/spec/sandbox/doc/block_helper.rb +3 -0
  74. data/spec/sandbox/doc/config.rb +1 -0
  75. data/spec/sandbox/doc/config.yaml.tt +1 -0
  76. data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
  77. data/spec/sandbox/enum.thor +10 -0
  78. data/spec/sandbox/group.thor +128 -0
  79. data/spec/sandbox/invoke.thor +131 -0
  80. data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
  81. data/spec/sandbox/preserve/script.sh +3 -0
  82. data/spec/sandbox/script.thor +220 -0
  83. data/spec/sandbox/subcommand.thor +17 -0
  84. data/spec/shell/basic_spec.rb +107 -86
  85. data/spec/shell/color_spec.rb +32 -8
  86. data/spec/shell/html_spec.rb +3 -4
  87. data/spec/shell_spec.rb +7 -7
  88. data/spec/subcommand_spec.rb +20 -2
  89. data/spec/thor_spec.rb +111 -97
  90. data/spec/util_spec.rb +30 -30
  91. data/thor.gemspec +14 -14
  92. metadata +69 -25
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  describe Thor::Shell do
4
4
  def shell
@@ -7,29 +7,29 @@ describe Thor::Shell do
7
7
 
8
8
  describe "#initialize" do
9
9
  it "sets shell value" do
10
- base = MyCounter.new [1, 2], { }, :shell => shell
10
+ base = MyCounter.new [1, 2], {}, :shell => shell
11
11
  expect(base.shell).to eq(shell)
12
12
  end
13
13
 
14
14
  it "sets the base value on the shell if an accessor is available" do
15
- base = MyCounter.new [1, 2], { }, :shell => shell
15
+ base = MyCounter.new [1, 2], {}, :shell => shell
16
16
  expect(shell.base).to eq(base)
17
17
  end
18
18
  end
19
19
 
20
20
  describe "#shell" do
21
21
  it "returns the shell in use" do
22
- expect(MyCounter.new([1,2]).shell).to be_kind_of(Thor::Base.shell)
22
+ expect(MyCounter.new([1, 2]).shell).to be_kind_of(Thor::Base.shell)
23
23
  end
24
24
 
25
25
  it "uses $THOR_SHELL" do
26
26
  class Thor::Shell::TestShell < Thor::Shell::Basic; end
27
27
 
28
28
  expect(Thor::Base.shell).to eq(shell.class)
29
- ENV['THOR_SHELL'] = 'TestShell'
29
+ ENV["THOR_SHELL"] = "TestShell"
30
30
  Thor::Base.shell = nil
31
31
  expect(Thor::Base.shell).to eq(Thor::Shell::TestShell)
32
- ENV['THOR_SHELL'] = ''
32
+ ENV["THOR_SHELL"] = ""
33
33
  Thor::Base.shell = shell.class
34
34
  expect(Thor::Base.shell).to eq(shell.class)
35
35
  end
@@ -37,7 +37,7 @@ describe Thor::Shell do
37
37
 
38
38
  describe "with_padding" do
39
39
  it "uses padding for inside block outputs" do
40
- base = MyCounter.new([1,2])
40
+ base = MyCounter.new([1, 2])
41
41
  base.with_padding do
42
42
  expect(capture(:stdout) { base.say_status :padding, "cool" }.strip).to eq("padding cool")
43
43
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  describe Thor do
4
4
 
@@ -18,13 +18,31 @@ describe Thor do
18
18
  end
19
19
 
20
20
  it "ignores unknown options (the subcommand class will handle them)" do
21
- expect(capture(:stdout) { Scripts::MyDefaults.start(%w[barn paint blue --coats 4])}.strip).to eq("4 coats of blue paint")
21
+ expect(capture(:stdout) { Scripts::MyDefaults.start(%w[barn paint blue --coats 4]) }.strip).to eq("4 coats of blue paint")
22
22
  end
23
23
 
24
24
  it "passes parsed options to subcommands" do
25
25
  output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --opt output]) }
26
26
  expect(output).to eq("output")
27
27
  end
28
+
29
+ it "accepts the help switch and calls the help command on the subcommand" do
30
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt --help]) }
31
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help print_opt]) }
32
+ expect(output).to eq(sub_help)
33
+ end
34
+
35
+ it "accepts the help short switch and calls the help command on the subcommand" do
36
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub print_opt -h]) }
37
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help print_opt]) }
38
+ expect(output).to eq(sub_help)
39
+ end
40
+
41
+ it "the help command on the subcommand and after it should result in the same output" do
42
+ output = capture(:stdout) { TestSubcommands::Parent.start(%w[sub help])}
43
+ sub_help = capture(:stdout) { TestSubcommands::Parent.start(%w[help sub])}
44
+ expect(output).to eq(sub_help)
45
+ end
28
46
  end
29
47
 
30
48
  end
@@ -1,61 +1,61 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  describe Thor do
4
4
  describe "#method_option" do
5
5
  it "sets options to the next method to be invoked" do
6
- args = ["foo", "bar", "--force"]
7
- arg, options = MyScript.start(args)
8
- expect(options).to eq({ "force" => true })
6
+ args = %w[foo bar --force]
7
+ _, options = MyScript.start(args)
8
+ expect(options).to eq("force" => true)
9
9
  end
10
10
 
11
11
  describe ":lazy_default" do
12
12
  it "is absent when option is not specified" do
13
- arg, options = MyScript.start(["with_optional"])
13
+ _, options = MyScript.start(%w[with_optional])
14
14
  expect(options).to eq({})
15
15
  end
16
16
 
17
17
  it "sets a default that can be overridden for strings" do
18
- arg, options = MyScript.start(["with_optional", "--lazy"])
19
- expect(options).to eq({ "lazy" => "yes" })
18
+ _, options = MyScript.start(%w[with_optional --lazy])
19
+ expect(options).to eq("lazy" => "yes")
20
20
 
21
- arg, options = MyScript.start(["with_optional", "--lazy", "yesyes!"])
22
- expect(options).to eq({ "lazy" => "yesyes!" })
21
+ _, options = MyScript.start(%w[with_optional --lazy yesyes!])
22
+ expect(options).to eq("lazy" => "yesyes!")
23
23
  end
24
24
 
25
25
  it "sets a default that can be overridden for numerics" do
26
- arg, options = MyScript.start(["with_optional", "--lazy-numeric"])
27
- expect(options).to eq({ "lazy_numeric" => 42 })
26
+ _, options = MyScript.start(%w[with_optional --lazy-numeric])
27
+ expect(options).to eq("lazy_numeric" => 42)
28
28
 
29
- arg, options = MyScript.start(["with_optional", "--lazy-numeric", 20000])
30
- expect(options).to eq({ "lazy_numeric" => 20000 })
29
+ _, options = MyScript.start(%w[with_optional --lazy-numeric 20000])
30
+ expect(options).to eq("lazy_numeric" => 20_000)
31
31
  end
32
32
 
33
33
  it "sets a default that can be overridden for arrays" do
34
- arg, options = MyScript.start(["with_optional", "--lazy-array"])
35
- expect(options).to eq({ "lazy_array" => %w[eat at joes] })
34
+ _, options = MyScript.start(%w[with_optional --lazy-array])
35
+ expect(options).to eq("lazy_array" => %w[eat at joes])
36
36
 
37
- arg, options = MyScript.start(["with_optional", "--lazy-array", "hello", "there"])
38
- expect(options).to eq({ "lazy_array" => %w[hello there] })
37
+ _, options = MyScript.start(%w[with_optional --lazy-array hello there])
38
+ expect(options).to eq("lazy_array" => %w[hello there])
39
39
  end
40
40
 
41
41
  it "sets a default that can be overridden for hashes" do
42
- arg, options = MyScript.start(["with_optional", "--lazy-hash"])
43
- expect(options).to eq({ "lazy_hash" => {'swedish' => 'meatballs'} })
42
+ _, options = MyScript.start(%w[with_optional --lazy-hash])
43
+ expect(options).to eq("lazy_hash" => {"swedish" => "meatballs"})
44
44
 
45
- arg, options = MyScript.start(["with_optional", "--lazy-hash", "polish:sausage"])
46
- expect(options).to eq({ "lazy_hash" => {'polish' => 'sausage'} })
45
+ _, options = MyScript.start(%w[with_optional --lazy-hash polish:sausage])
46
+ expect(options).to eq("lazy_hash" => {"polish" => "sausage"})
47
47
  end
48
48
  end
49
49
 
50
50
  describe "when :for is supplied" do
51
51
  it "updates an already defined command" do
52
- args, options = MyChildScript.start(["animal", "horse", "--other=fish"])
52
+ _, options = MyChildScript.start(%w[animal horse --other=fish])
53
53
  expect(options[:other]).to eq("fish")
54
54
  end
55
55
 
56
56
  describe "and the target is on the parent class" do
57
57
  it "updates an already defined command" do
58
- args = ["example_default_command", "my_param", "--new-option=verified"]
58
+ args = %w[example_default_command my_param --new-option=verified]
59
59
  options = Scripts::MyScript.start(args)
60
60
  expect(options[:new_option]).to eq("verified")
61
61
  end
@@ -81,7 +81,7 @@ describe Thor do
81
81
  end
82
82
 
83
83
  it "invokes the default command if no command is specified even if switches are given" do
84
- expect(MyScript.start(["--with", "option"])).to eq({"with"=>"option"})
84
+ expect(MyScript.start(%w[--with option])).to eq("with" => "option")
85
85
  end
86
86
 
87
87
  it "inherits the default command from parent" do
@@ -98,37 +98,37 @@ describe Thor do
98
98
 
99
99
  desc "exec", "Run a command"
100
100
  def exec(*args)
101
- return options, args
101
+ [options, args]
102
102
  end
103
103
 
104
104
  desc "boring", "An ordinary command"
105
105
  def boring(*args)
106
- return options, args
106
+ [options, args]
107
107
  end
108
108
  end
109
109
 
110
110
  it "passes remaining args to command when it encounters a non-option" do
111
- expect(my_script.start(%w[exec command --verbose])).to eq [{}, ["command", "--verbose"]]
111
+ expect(my_script.start(%w[exec command --verbose])).to eq [{}, %w[command --verbose]]
112
112
  end
113
113
 
114
114
  it "passes remaining args to command when it encounters an unknown option" do
115
- expect(my_script.start(%w[exec --foo command --bar])).to eq [{}, ["--foo", "command", "--bar"]]
115
+ expect(my_script.start(%w[exec --foo command --bar])).to eq [{}, %w[--foo command --bar]]
116
116
  end
117
117
 
118
118
  it "still accepts options that are given before non-options" do
119
- expect(my_script.start(%w[exec --verbose command --foo])).to eq [{"verbose" => true}, ["command", "--foo"]]
119
+ expect(my_script.start(%w[exec --verbose command --foo])).to eq [{"verbose" => true}, %w[command --foo]]
120
120
  end
121
121
 
122
122
  it "still accepts options that require a value" do
123
- expect(my_script.start(%w[exec --mode rashly command])).to eq [{"mode" => "rashly"}, ["command"]]
123
+ expect(my_script.start(%w[exec --mode rashly command])).to eq [{"mode" => "rashly"}, %w[command]]
124
124
  end
125
125
 
126
126
  it "still passes everything after -- to command" do
127
- expect(my_script.start(%w[exec -- --verbose])).to eq [{}, ["--verbose"]]
127
+ expect(my_script.start(%w[exec -- --verbose])).to eq [{}, %w[--verbose]]
128
128
  end
129
129
 
130
130
  it "does not affect ordinary commands" do
131
- expect(my_script.start(%w[boring command --verbose])).to eq [{"verbose" => true}, ["command"]]
131
+ expect(my_script.start(%w[boring command --verbose])).to eq [{"verbose" => true}, %w[command]]
132
132
  end
133
133
 
134
134
  context "when provided with multiple command names" do
@@ -136,9 +136,9 @@ describe Thor do
136
136
  stop_on_unknown_option! :foo, :bar
137
137
  end
138
138
  it "affects all specified commands" do
139
- expect(klass.stop_on_unknown_option?(mock :name => "foo")).to be_true
140
- expect(klass.stop_on_unknown_option?(mock :name => "bar")).to be_true
141
- expect(klass.stop_on_unknown_option?(mock :name => "baz")).to be_false
139
+ expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be true
140
+ expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be true
141
+ expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be false
142
142
  end
143
143
  end
144
144
 
@@ -148,21 +148,25 @@ describe Thor do
148
148
  stop_on_unknown_option! :bar
149
149
  end
150
150
  it "affects all specified commands" do
151
- expect(klass.stop_on_unknown_option?(mock :name => "foo")).to be_true
152
- expect(klass.stop_on_unknown_option?(mock :name => "bar")).to be_true
153
- expect(klass.stop_on_unknown_option?(mock :name => "baz")).to be_false
151
+ expect(klass.stop_on_unknown_option?(double(:name => "foo"))).to be true
152
+ expect(klass.stop_on_unknown_option?(double(:name => "bar"))).to be true
153
+ expect(klass.stop_on_unknown_option?(double(:name => "baz"))).to be false
154
154
  end
155
155
  end
156
+
157
+ it "doesn't break new" do
158
+ expect(my_script.new).to be_a(Thor)
159
+ end
156
160
  end
157
161
 
158
162
  describe "#map" do
159
163
  it "calls the alias of a method if one is provided" do
160
- expect(MyScript.start(["-T", "fish"])).to eq(["fish"])
164
+ expect(MyScript.start(%w[-T fish])).to eq(%w[fish])
161
165
  end
162
166
 
163
- it "calls the alias of a method if several are provided via .map" do
164
- expect(MyScript.start(["-f", "fish"])).to eq(["fish", {}])
165
- expect(MyScript.start(["--foo", "fish"])).to eq(["fish", {}])
167
+ it "calls the alias of a method if several are provided via #map" do
168
+ expect(MyScript.start(%w[-f fish])).to eq(["fish", {}])
169
+ expect(MyScript.start(%w[--foo fish])).to eq(["fish", {}])
166
170
  end
167
171
 
168
172
  it "inherits all mappings from parent" do
@@ -172,27 +176,27 @@ describe Thor do
172
176
 
173
177
  describe "#package_name" do
174
178
  it "provides a proper description for a command when the package_name is assigned" do
175
- content = capture(:stdout) { PackageNameScript.start(["help"]) }
179
+ content = capture(:stdout) { PackageNameScript.start(%w[help]) }
176
180
  expect(content).to match(/Baboon commands:/m)
177
181
  end
178
182
 
179
183
  # TODO: remove this, might be redundant, just wanted to prove full coverage
180
184
  it "provides a proper description for a command when the package_name is NOT assigned" do
181
- content = capture(:stdout) { MyScript.start(["help"]) }
185
+ content = capture(:stdout) { MyScript.start(%w[help]) }
182
186
  expect(content).to match(/Commands:/m)
183
187
  end
184
188
  end
185
189
 
186
190
  describe "#desc" do
187
191
  it "provides description for a command" do
188
- content = capture(:stdout) { MyScript.start(["help"]) }
192
+ content = capture(:stdout) { MyScript.start(%w[help]) }
189
193
  expect(content).to match(/thor my_script:zoo\s+# zoo around/m)
190
194
  end
191
195
 
192
196
  it "provides no namespace if $thor_runner is false" do
193
197
  begin
194
198
  $thor_runner = false
195
- content = capture(:stdout) { MyScript.start(["help"]) }
199
+ content = capture(:stdout) { MyScript.start(%w[help]) }
196
200
  expect(content).to match(/thor zoo\s+# zoo around/m)
197
201
  ensure
198
202
  $thor_runner = true
@@ -201,17 +205,17 @@ describe Thor do
201
205
 
202
206
  describe "when :for is supplied" do
203
207
  it "overwrites a previous defined command" do
204
- expect(capture(:stdout) { MyChildScript.start(["help"]) }).to match(/animal KIND \s+# fish around/m)
208
+ expect(capture(:stdout) { MyChildScript.start(%w[help]) }).to match(/animal KIND \s+# fish around/m)
205
209
  end
206
210
  end
207
211
 
208
212
  describe "when :hide is supplied" do
209
213
  it "does not show the command in help" do
210
- expect(capture(:stdout) { MyScript.start(["help"]) }).not_to match(/this is hidden/m)
214
+ expect(capture(:stdout) { MyScript.start(%w[help]) }).not_to match(/this is hidden/m)
211
215
  end
212
216
 
213
- it "but the command is still invokcable not show the command in help" do
214
- expect(MyScript.start(["hidden", "yesyes"])).to eq(["yesyes"])
217
+ it "but the command is still invokable, does not show the command in help" do
218
+ expect(MyScript.start(%w[hidden yesyes])).to eq(%w[yesyes])
215
219
  end
216
220
  end
217
221
  end
@@ -224,30 +228,30 @@ describe Thor do
224
228
  end
225
229
 
226
230
  it "overwrites default options if called on the method scope" do
227
- args = ["zoo", "--force", "--param", "feathers"]
231
+ args = %w[zoo --force --param feathers]
228
232
  options = MyChildScript.start(args)
229
- expect(options).to eq({ "force" => true, "param" => "feathers" })
233
+ expect(options).to eq("force" => true, "param" => "feathers")
230
234
  end
231
235
 
232
236
  it "allows default options to be merged with method options" do
233
- args = ["animal", "bird", "--force", "--param", "1.0", "--other", "tweets"]
237
+ args = %w[animal bird --force --param 1.0 --other tweets]
234
238
  arg, options = MyChildScript.start(args)
235
- expect(arg).to eq('bird')
236
- expect(options).to eq({ "force"=>true, "param"=>1.0, "other"=>"tweets" })
239
+ expect(arg).to eq("bird")
240
+ expect(options).to eq("force" => true, "param" => 1.0, "other" => "tweets")
237
241
  end
238
242
  end
239
243
 
240
244
  describe "#start" do
241
245
  it "calls a no-param method when no params are passed" do
242
- expect(MyScript.start(["zoo"])).to eq(true)
246
+ expect(MyScript.start(%w[zoo])).to eq(true)
243
247
  end
244
248
 
245
249
  it "calls a single-param method when a single param is passed" do
246
- expect(MyScript.start(["animal", "fish"])).to eq(["fish"])
250
+ expect(MyScript.start(%w[animal fish])).to eq(%w[fish])
247
251
  end
248
252
 
249
253
  it "does not set options in attributes" do
250
- expect(MyScript.start(["with_optional", "--all"])).to eq([nil, { "all" => true }, []])
254
+ expect(MyScript.start(%w[with_optional --all])).to eq([nil, {"all" => true}, []])
251
255
  end
252
256
 
253
257
  it "raises an error if the wrong number of params are provided" do
@@ -255,56 +259,66 @@ describe Thor do
255
259
  stderr = capture(:stderr) { Scripts::Arities.start(args) }
256
260
  expect(stderr.strip).to eq(msg)
257
261
  end
258
- arity_asserter.call ["zero_args", "one" ], %Q'ERROR: thor zero_args was called with arguments ["one"]\nUsage: "thor scripts:arities:zero_args".'
259
- arity_asserter.call ["one_arg" ], %Q'ERROR: thor one_arg was called with no arguments\nUsage: "thor scripts:arities:one_arg ARG".'
260
- arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: thor one_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG".'
261
- arity_asserter.call ["one_arg", "one", "two" ], %Q'ERROR: thor one_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:one_arg ARG".'
262
- arity_asserter.call ["two_args", "one" ], %Q'ERROR: thor two_args was called with arguments ["one"]\nUsage: "thor scripts:arities:two_args ARG1 ARG2".'
263
- arity_asserter.call ["optional_arg", "one", "two" ], %Q'ERROR: thor optional_arg was called with arguments ["one", "two"]\nUsage: "thor scripts:arities:optional_arg [ARG]".'
262
+ arity_asserter.call %w[zero_args one], %Q(ERROR: "thor zero_args" was called with arguments ["one"]
263
+ Usage: "thor scripts:arities:zero_args")
264
+ arity_asserter.call %w[one_arg], %Q(ERROR: "thor one_arg" was called with no arguments
265
+ Usage: "thor scripts:arities:one_arg ARG")
266
+ arity_asserter.call %w[one_arg one two], %Q(ERROR: "thor one_arg" was called with arguments ["one", "two"]
267
+ Usage: "thor scripts:arities:one_arg ARG")
268
+ arity_asserter.call %w[one_arg one two], %Q(ERROR: "thor one_arg" was called with arguments ["one", "two"]
269
+ Usage: "thor scripts:arities:one_arg ARG")
270
+ arity_asserter.call %w[two_args one], %Q(ERROR: "thor two_args" was called with arguments ["one"]
271
+ Usage: "thor scripts:arities:two_args ARG1 ARG2")
272
+ arity_asserter.call %w[optional_arg one two], %Q(ERROR: "thor optional_arg" was called with arguments ["one", "two"]
273
+ Usage: "thor scripts:arities:optional_arg [ARG]")
264
274
  end
265
275
 
266
276
  it "raises an error if the invoked command does not exist" do
267
- expect(capture(:stderr) { Amazing.start(["animal"]) }.strip).to eq('Could not find command "animal" in "amazing" namespace.')
277
+ expect(capture(:stderr) { Amazing.start(%w[animal]) }.strip).to eq('Could not find command "animal" in "amazing" namespace.')
268
278
  end
269
279
 
270
280
  it "calls method_missing if an unknown method is passed in" do
271
- expect(MyScript.start(["unk", "hello"])).to eq([:unk, ["hello"]])
281
+ expect(MyScript.start(%w[unk hello])).to eq([:unk, %w[hello]])
272
282
  end
273
283
 
274
284
  it "does not call a private method no matter what" do
275
- expect(capture(:stderr) { MyScript.start(["what"]) }.strip).to eq('Could not find command "what" in "my_script" namespace.')
285
+ expect(capture(:stderr) { MyScript.start(%w[what]) }.strip).to eq('Could not find command "what" in "my_script" namespace.')
276
286
  end
277
287
 
278
288
  it "uses command default options" do
279
- options = MyChildScript.start(["animal", "fish"]).last
280
- expect(options).to eq({ "other" => "method default" })
289
+ options = MyChildScript.start(%w[animal fish]).last
290
+ expect(options).to eq("other" => "method default")
281
291
  end
282
292
 
283
293
  it "raises when an exception happens within the command call" do
284
- expect{ MyScript.start(["call_myself_with_wrong_arity"]) }.to raise_error(ArgumentError)
294
+ expect { MyScript.start(%w[call_myself_with_wrong_arity]) }.to raise_error(ArgumentError)
285
295
  end
286
296
 
287
297
  context "when the user enters an unambiguous substring of a command" do
288
298
  it "invokes a command" do
289
- expect(MyScript.start(["z"])).to eq(MyScript.start(["zoo"]))
299
+ expect(MyScript.start(%w[z])).to eq(MyScript.start(%w[zoo]))
290
300
  end
291
301
 
292
302
  it "invokes a command, even when there's an alias it resolves to the same command" do
293
- expect(MyScript.start(["hi", "arg"])).to eq(MyScript.start(["hidden", "arg"]))
303
+ expect(MyScript.start(%w[hi arg])).to eq(MyScript.start(%w[hidden arg]))
294
304
  end
295
305
 
296
306
  it "invokes an alias" do
297
- expect(MyScript.start(["animal_pri"])).to eq(MyScript.start(["zoo"]))
307
+ expect(MyScript.start(%w[animal_pri])).to eq(MyScript.start(%w[zoo]))
298
308
  end
299
309
  end
300
310
 
301
311
  context "when the user enters an ambiguous substring of a command" do
302
- it "raises an exception that explains the ambiguity" do
303
- expect{ MyScript.start(["call"]) }.to raise_error(ArgumentError, 'Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]')
312
+ it "raises an exception and displays a message that explains the ambiguity" do
313
+ shell = Thor::Base.shell.new
314
+ expect(shell).to receive(:error).with("Ambiguous command call matches [call_myself_with_wrong_arity, call_unexistent_method]")
315
+ MyScript.start(%w[call], :shell => shell)
304
316
  end
305
317
 
306
318
  it "raises an exception when there is an alias" do
307
- expect{ MyScript.start(["f"]) }.to raise_error(ArgumentError, 'Ambiguous command f matches [foo, fu]')
319
+ shell = Thor::Base.shell.new
320
+ expect(shell).to receive(:error).with("Ambiguous command f matches [foo, fu]")
321
+ MyScript.start(%w[f], :shell => shell)
308
322
  end
309
323
  end
310
324
 
@@ -329,7 +343,7 @@ describe Thor do
329
343
  end
330
344
 
331
345
  it "uses the maximum terminal size to show commands" do
332
- @shell.should_receive(:terminal_width).and_return(80)
346
+ expect(@shell).to receive(:terminal_width).and_return(80)
333
347
  content = capture(:stdout) { MyScript.help(shell) }
334
348
  expect(content).to match(/aaa\.\.\.$/)
335
349
  end
@@ -371,9 +385,9 @@ END
371
385
  end
372
386
 
373
387
  it "raises an error if the command can't be found" do
374
- expect {
388
+ expect do
375
389
  MyScript.command_help(shell, "unknown")
376
- }.to raise_error(Thor::UndefinedCommandError, 'Could not find command "unknown" in "my_script" namespace.')
390
+ end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "unknown" in "my_script" namespace.')
377
391
  end
378
392
 
379
393
  it "normalizes names before claiming they don't exist" do
@@ -393,36 +407,36 @@ HELP
393
407
  end
394
408
 
395
409
  it "doesn't assign the long description to the next command without one" do
396
- expect(capture(:stdout) {
410
+ expect(capture(:stdout) do
397
411
  MyScript.command_help(shell, "name_with_dashes")
398
- }).not_to match(/so very long/i)
412
+ end).not_to match(/so very long/i)
399
413
  end
400
414
  end
401
415
 
402
416
  describe "instance method" do
403
417
  it "calls the class method" do
404
- expect(capture(:stdout) { MyScript.start(["help"]) }).to match(/Commands:/)
418
+ expect(capture(:stdout) { MyScript.start(%w[help]) }).to match(/Commands:/)
405
419
  end
406
420
 
407
421
  it "calls the class method" do
408
- expect(capture(:stdout) { MyScript.start(["help", "foo"]) }).to match(/Usage:/)
422
+ expect(capture(:stdout) { MyScript.start(%w[help foo]) }).to match(/Usage:/)
409
423
  end
410
424
  end
411
425
  end
412
426
 
413
427
  describe "when creating commands" do
414
428
  it "prints a warning if a public method is created without description or usage" do
415
- expect(capture(:stdout) {
429
+ expect(capture(:stdout) do
416
430
  klass = Class.new(Thor)
417
431
  klass.class_eval "def hello_from_thor; end"
418
- }).to match(/\[WARNING\] Attempted to create command "hello_from_thor" without usage or description/)
432
+ end).to match(/\[WARNING\] Attempted to create command "hello_from_thor" without usage or description/)
419
433
  end
420
434
 
421
435
  it "does not print if overwriting a previous command" do
422
- expect(capture(:stdout) {
436
+ expect(capture(:stdout) do
423
437
  klass = Class.new(Thor)
424
438
  klass.class_eval "def help; end"
425
- }).to be_empty
439
+ end).to be_empty
426
440
  end
427
441
  end
428
442
 
@@ -437,9 +451,9 @@ HELP
437
451
  end
438
452
  end
439
453
 
440
- expect(klass.start(["hi", "jose"])).to eq("Hi jose")
441
- expect(klass.start(["hi", "jose", "--loud"])).to eq("Hi JOSE")
442
- expect(klass.start(["hi", "--loud", "jose"])).to eq("Hi JOSE")
454
+ expect(klass.start(%w[hi jose])).to eq("Hi jose")
455
+ expect(klass.start(%w[hi jose --loud])).to eq("Hi JOSE")
456
+ expect(klass.start(%w[hi --loud jose])).to eq("Hi JOSE")
443
457
  end
444
458
 
445
459
  it "passes through unknown options" do
@@ -450,8 +464,8 @@ HELP
450
464
  end
451
465
  end
452
466
 
453
- expect(klass.start(["unknown", "foo", "--bar", "baz", "bat", "--bam"])).to eq(["foo", "--bar", "baz", "bat", "--bam"])
454
- expect(klass.start(["unknown", "--bar", "baz"])).to eq(["--bar", "baz"])
467
+ expect(klass.start(%w[unknown foo --bar baz bat --bam])).to eq(%w[foo --bar baz bat --bam])
468
+ expect(klass.start(%w[unknown --bar baz])).to eq(%w[--bar baz])
455
469
  end
456
470
 
457
471
  it "does not pass through unknown options with strict args" do
@@ -464,8 +478,8 @@ HELP
464
478
  end
465
479
  end
466
480
 
467
- expect(klass.start(["unknown", "--bar", "baz"])).to eq([])
468
- expect(klass.start(["unknown", "foo", "--bar", "baz"])).to eq(["foo"])
481
+ expect(klass.start(%w[unknown --bar baz])).to eq([])
482
+ expect(klass.start(%w[unknown foo --bar baz])).to eq(%w[foo])
469
483
  end
470
484
 
471
485
  it "strict args works in the inheritance chain" do
@@ -480,12 +494,12 @@ HELP
480
494
  end
481
495
  end
482
496
 
483
- expect(klass.start(["unknown", "--bar", "baz"])).to eq([])
484
- expect(klass.start(["unknown", "foo", "--bar", "baz"])).to eq(["foo"])
497
+ expect(klass.start(%w[unknown --bar baz])).to eq([])
498
+ expect(klass.start(%w[unknown foo --bar baz])).to eq(%w[foo])
485
499
  end
486
500
 
487
501
  it "send as a command name" do
488
- expect(MyScript.start(["send"])).to eq(true)
502
+ expect(MyScript.start(%w[send])).to eq(true)
489
503
  end
490
504
  end
491
505
  end