thor 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 +1,5 @@
1
- require 'helper'
2
- require 'thor/actions'
1
+ require "helper"
2
+ require "thor/actions"
3
3
 
4
4
  describe Thor::Actions::InjectIntoFile do
5
5
  before do
@@ -7,12 +7,12 @@ describe Thor::Actions::InjectIntoFile do
7
7
  ::FileUtils.cp_r(source_root, destination_root)
8
8
  end
9
9
 
10
- def invoker(options={})
11
- @invoker ||= MyCounter.new([1,2], options, { :destination_root => destination_root })
10
+ def invoker(options = {})
11
+ @invoker ||= MyCounter.new([1, 2], options, :destination_root => destination_root)
12
12
  end
13
13
 
14
14
  def revoker
15
- @revoker ||= MyCounter.new([1,2], {}, { :destination_root => destination_root, :behavior => :revoke })
15
+ @revoker ||= MyCounter.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke)
16
16
  end
17
17
 
18
18
  def invoke!(*args, &block)
@@ -56,7 +56,7 @@ describe Thor::Actions::InjectIntoFile do
56
56
  expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
57
57
  end
58
58
 
59
- it "does not change the file if already include content" do
59
+ it "does not change the file if already includes content" do
60
60
  invoke! "doc/README", :before => "__end__" do
61
61
  "more content\n"
62
62
  end
@@ -70,7 +70,7 @@ describe Thor::Actions::InjectIntoFile do
70
70
  expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n")
71
71
  end
72
72
 
73
- it "does change the file if already include content and :force == true" do
73
+ it "does change the file if already includes content and :force is true" do
74
74
  invoke! "doc/README", :before => "__end__" do
75
75
  "more content\n"
76
76
  end
@@ -87,40 +87,40 @@ describe Thor::Actions::InjectIntoFile do
87
87
  end
88
88
 
89
89
  describe "#revoke!" do
90
- it "substracts the destination file after injection" do
90
+ it "subtracts the destination file after injection" do
91
91
  invoke! "doc/README", "\nmore content", :after => "__start__"
92
92
  revoke! "doc/README", "\nmore content", :after => "__start__"
93
93
  expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
94
94
  end
95
95
 
96
- it "substracts the destination file before injection" do
96
+ it "subtracts the destination file before injection" do
97
97
  invoke! "doc/README", "more content\n", :before => "__start__"
98
98
  revoke! "doc/README", "more content\n", :before => "__start__"
99
99
  expect(File.read(file)).to eq("__start__\nREADME\n__end__\n")
100
100
  end
101
101
 
102
- it "substracts even with double after injection" do
102
+ it "subtracts even with double after injection" do
103
103
  invoke! "doc/README", "\nmore content", :after => "__start__"
104
104
  invoke! "doc/README", "\nanother stuff", :after => "__start__"
105
105
  revoke! "doc/README", "\nmore content", :after => "__start__"
106
106
  expect(File.read(file)).to eq("__start__\nanother stuff\nREADME\n__end__\n")
107
107
  end
108
108
 
109
- it "substracts even with double before injection" do
109
+ it "subtracts even with double before injection" do
110
110
  invoke! "doc/README", "more content\n", :before => "__start__"
111
111
  invoke! "doc/README", "another stuff\n", :before => "__start__"
112
112
  revoke! "doc/README", "more content\n", :before => "__start__"
113
113
  expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
114
114
  end
115
115
 
116
- it "substracts when prepending" do
116
+ it "subtracts when prepending" do
117
117
  invoke! "doc/README", "more content\n", :after => /\A/
118
118
  invoke! "doc/README", "another stuff\n", :after => /\A/
119
119
  revoke! "doc/README", "more content\n", :after => /\A/
120
120
  expect(File.read(file)).to eq("another stuff\n__start__\nREADME\n__end__\n")
121
121
  end
122
122
 
123
- it "substracts when appending" do
123
+ it "subtracts when appending" do
124
124
  invoke! "doc/README", "more content\n", :before => /\z/
125
125
  invoke! "doc/README", "another stuff\n", :before => /\z/
126
126
  revoke! "doc/README", "more content\n", :before => /\z/
@@ -1,8 +1,8 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  describe Thor::Actions do
4
- def runner(options={})
5
- @runner ||= MyCounter.new([1], options, { :destination_root => destination_root })
4
+ def runner(options = {})
5
+ @runner ||= MyCounter.new([1], options, :destination_root => destination_root)
6
6
  end
7
7
 
8
8
  def action(*args, &block)
@@ -32,17 +32,17 @@ describe Thor::Actions do
32
32
  end
33
33
 
34
34
  it "when behavior is set to force, overwrite options" do
35
- runner = MyCounter.new([1], { :force => false, :skip => true }, :behavior => :force)
35
+ runner = MyCounter.new([1], {:force => false, :skip => true}, :behavior => :force)
36
36
  expect(runner.behavior).to eq(:invoke)
37
- expect(runner.options.force).to be_true
38
- expect(runner.options.skip).not_to be_true
37
+ expect(runner.options.force).to be true
38
+ expect(runner.options.skip).not_to be true
39
39
  end
40
40
 
41
41
  it "when behavior is set to skip, overwrite options" do
42
- runner = MyCounter.new([1], ["--force"], :behavior => :skip)
42
+ runner = MyCounter.new([1], %w[--force], :behavior => :skip)
43
43
  expect(runner.behavior).to eq(:invoke)
44
- expect(runner.options.force).not_to be_true
45
- expect(runner.options.skip).to be_true
44
+ expect(runner.options.force).not_to be true
45
+ expect(runner.options.skip).to be true
46
46
  end
47
47
  end
48
48
 
@@ -83,11 +83,11 @@ describe Thor::Actions do
83
83
  end
84
84
 
85
85
  it "creates proper relative paths for absolute file location" do
86
- expect(runner.relative_to_original_destination_root('/test/file')).to eq("/test/file")
86
+ expect(runner.relative_to_original_destination_root("/test/file")).to eq("/test/file")
87
87
  end
88
88
 
89
- it "does not fail with files constaining regexp characters" do
90
- runner = MyCounter.new([1], {}, { :destination_root => File.join(destination_root, "fo[o-b]ar") })
89
+ it "does not fail with files containing regexp characters" do
90
+ runner = MyCounter.new([1], {}, :destination_root => File.join(destination_root, "fo[o-b]ar"))
91
91
  expect(runner.relative_to_original_destination_root("bar")).to eq("bar")
92
92
  end
93
93
 
@@ -114,14 +114,14 @@ describe Thor::Actions do
114
114
 
115
115
  describe "#find_in_source_paths" do
116
116
  it "raises an error if source path is empty" do
117
- expect {
117
+ expect do
118
118
  A.new.find_in_source_paths("foo")
119
- }.to raise_error(Thor::Error, /Currently you have no source paths/)
119
+ end.to raise_error(Thor::Error, /Currently you have no source paths/)
120
120
  end
121
121
 
122
122
  it "finds a template inside the source path" do
123
123
  expect(runner.find_in_source_paths("doc")).to eq(File.expand_path("doc", source_root))
124
- expect{ runner.find_in_source_paths("README") }.to raise_error
124
+ expect { runner.find_in_source_paths("README") }.to raise_error
125
125
 
126
126
  new_path = File.join(source_root, "doc")
127
127
  runner.instance_variable_set(:@source_paths, nil)
@@ -146,37 +146,37 @@ describe Thor::Actions do
146
146
 
147
147
  it "creates the directory if it does not exist" do
148
148
  runner.inside("foo") do
149
- expect(File.exists?(file)).to be_true
149
+ expect(File.exist?(file)).to be true
150
150
  end
151
151
  end
152
152
 
153
153
  describe "when pretending" do
154
154
  it "no directories should be created" do
155
155
  runner.inside("bar", :pretend => true) {}
156
- expect(File.exists?("bar")).to be_false
156
+ expect(File.exist?("bar")).to be false
157
157
  end
158
158
  end
159
159
 
160
160
  describe "when verbose" do
161
161
  it "logs status" do
162
- expect(capture(:stdout) {
162
+ expect(capture(:stdout) do
163
163
  runner.inside("foo", :verbose => true) {}
164
- }).to match(/inside foo/)
164
+ end).to match(/inside foo/)
165
165
  end
166
166
 
167
167
  it "uses padding in next status" do
168
- expect(capture(:stdout) {
168
+ expect(capture(:stdout) do
169
169
  runner.inside("foo", :verbose => true) do
170
170
  runner.say_status :cool, :padding
171
171
  end
172
- }).to match(/cool padding/)
172
+ end).to match(/cool padding/)
173
173
  end
174
174
 
175
175
  it "removes padding after block" do
176
- expect(capture(:stdout) {
176
+ expect(capture(:stdout) do
177
177
  runner.inside("foo", :verbose => true) {}
178
178
  runner.say_status :no, :padding
179
- }).to match(/no padding/)
179
+ end).to match(/no padding/)
180
180
  end
181
181
  end
182
182
  end
@@ -196,7 +196,7 @@ describe Thor::Actions do
196
196
 
197
197
  it "returns to the previous state" do
198
198
  runner.inside("foo") do
199
- runner.in_root { }
199
+ runner.in_root {}
200
200
  expect(runner.destination_root).to eq(file)
201
201
  end
202
202
  end
@@ -208,27 +208,27 @@ describe Thor::Actions do
208
208
  @foo = "FOO"
209
209
  say_status :cool, :padding
210
210
  TEMPLATE
211
- @template.stub(:read).and_return(@template)
211
+ allow(@template).to receive(:read).and_return(@template)
212
212
 
213
- @file = '/'
214
- runner.stub(:open).and_return(@template)
213
+ @file = "/"
214
+ allow(runner).to receive(:open).and_return(@template)
215
215
  end
216
216
 
217
217
  it "accepts a URL as the path" do
218
218
  @file = "http://gist.github.com/103208.txt"
219
- runner.should_receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
219
+ expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
220
220
  action(:apply, @file)
221
221
  end
222
222
 
223
223
  it "accepts a secure URL as the path" do
224
224
  @file = "https://gist.github.com/103208.txt"
225
- runner.should_receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
225
+ expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template)
226
226
  action(:apply, @file)
227
227
  end
228
228
 
229
229
  it "accepts a local file path with spaces" do
230
230
  @file = File.expand_path("fixtures/path with spaces", File.dirname(__FILE__))
231
- runner.should_receive(:open).with(@file).and_return(@template)
231
+ expect(runner).to receive(:open).with(@file).and_return(@template)
232
232
  action(:apply, @file)
233
233
  end
234
234
 
@@ -254,7 +254,7 @@ describe Thor::Actions do
254
254
 
255
255
  describe "#run" do
256
256
  before do
257
- runner.should_receive(:system).with("ls")
257
+ expect(runner).to receive(:system).with("ls")
258
258
  end
259
259
 
260
260
  it "executes the command given" do
@@ -270,15 +270,15 @@ describe Thor::Actions do
270
270
  end
271
271
 
272
272
  it "accepts a color as status" do
273
- runner.shell.should_receive(:say_status).with(:run, 'ls from "."', :yellow)
273
+ expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow)
274
274
  action :run, "ls", :verbose => :yellow
275
275
  end
276
276
  end
277
277
 
278
278
  describe "#run_ruby_script" do
279
279
  before do
280
- Thor::Util.stub!(:ruby_command).and_return("/opt/jruby")
281
- runner.should_receive(:system).with("/opt/jruby script.rb")
280
+ allow(Thor::Util).to receive(:ruby_command).and_return("/opt/jruby")
281
+ expect(runner).to receive(:system).with("/opt/jruby script.rb")
282
282
  end
283
283
 
284
284
  it "executes the ruby script" do
@@ -296,35 +296,35 @@ describe Thor::Actions do
296
296
 
297
297
  describe "#thor" do
298
298
  it "executes the thor command" do
299
- runner.should_receive(:system).with("thor list")
299
+ expect(runner).to receive(:system).with("thor list")
300
300
  action :thor, :list, :verbose => true
301
301
  end
302
302
 
303
303
  it "converts extra arguments to command arguments" do
304
- runner.should_receive(:system).with("thor list foo bar")
304
+ expect(runner).to receive(:system).with("thor list foo bar")
305
305
  action :thor, :list, "foo", "bar"
306
306
  end
307
307
 
308
308
  it "converts options hash to switches" do
309
- runner.should_receive(:system).with("thor list foo bar --foo")
309
+ expect(runner).to receive(:system).with("thor list foo bar --foo")
310
310
  action :thor, :list, "foo", "bar", :foo => true
311
311
 
312
- runner.should_receive(:system).with("thor list --foo 1 2 3")
313
- action :thor, :list, :foo => [1,2,3]
312
+ expect(runner).to receive(:system).with("thor list --foo 1 2 3")
313
+ action :thor, :list, :foo => [1, 2, 3]
314
314
  end
315
315
 
316
316
  it "logs status" do
317
- runner.should_receive(:system).with("thor list")
317
+ expect(runner).to receive(:system).with("thor list")
318
318
  expect(action(:thor, :list)).to eq(" run thor list from \".\"\n")
319
319
  end
320
320
 
321
321
  it "does not log status if required" do
322
- runner.should_receive(:system).with("thor list --foo 1 2 3")
323
- expect(action(:thor, :list, :foo => [1,2,3], :verbose => false)).to be_empty
322
+ expect(runner).to receive(:system).with("thor list --foo 1 2 3")
323
+ expect(action(:thor, :list, :foo => [1, 2, 3], :verbose => false)).to be_empty
324
324
  end
325
325
 
326
326
  it "captures the output when :capture is given" do
327
- runner.should_receive(:`).with("thor foo bar")
327
+ expect(runner).to receive(:`).with("thor foo bar")
328
328
  action(:thor, "foo", "bar", :capture => true)
329
329
  end
330
330
  end
@@ -1,5 +1,5 @@
1
- require 'helper'
2
- require 'thor/base'
1
+ require "helper"
2
+ require "thor/base"
3
3
 
4
4
  class Amazing
5
5
  desc "hello", "say hello"
@@ -36,7 +36,7 @@ describe Thor::Base do
36
36
 
37
37
  it "creates options with indifferent access" do
38
38
  base = MyCounter.new [1, 2], :third => 3
39
- expect(base.options['third']).to eq(3)
39
+ expect(base.options["third"]).to eq(3)
40
40
  end
41
41
 
42
42
  it "creates options with magic predicates" do
@@ -54,39 +54,39 @@ describe Thor::Base do
54
54
 
55
55
  describe "#argument" do
56
56
  it "sets a value as required and creates an accessor for it" do
57
- expect(MyCounter.start(["1", "2", "--third", "3"])[0]).to eq(1)
58
- expect(Scripts::MyScript.start(["zoo", "my_special_param", "--param=normal_param"])).to eq("my_special_param")
57
+ expect(MyCounter.start(%w[1 2 --third 3])[0]).to eq(1)
58
+ expect(Scripts::MyScript.start(%w[zoo my_special_param --param=normal_param])).to eq("my_special_param")
59
59
  end
60
60
 
61
61
  it "does not set a value in the options hash" do
62
- expect(BrokenCounter.start(["1", "2", "--third", "3"])[0]).to be_nil
62
+ expect(BrokenCounter.start(%w[1 2 --third 3])[0]).to be nil
63
63
  end
64
64
  end
65
65
 
66
66
  describe "#arguments" do
67
67
  it "returns the arguments for the class" do
68
- expect(MyCounter.arguments).to have(2).items
68
+ expect(MyCounter.arguments.size).to be(2)
69
69
  end
70
70
  end
71
71
 
72
72
  describe ":aliases" do
73
73
  it "supports string aliases without a dash prefix" do
74
- expect(MyCounter.start(["1", "2", "-z", "3"])[4]).to eq(3)
74
+ expect(MyCounter.start(%w[1 2 -z 3])[4]).to eq(3)
75
75
  end
76
76
 
77
77
  it "supports symbol aliases" do
78
- expect(MyCounter.start(["1", "2", "-y", "3"])[5]).to eq(3)
79
- expect(MyCounter.start(["1", "2", "-r", "3"])[5]).to eq(3)
78
+ expect(MyCounter.start(%w[1 2 -y 3])[5]).to eq(3)
79
+ expect(MyCounter.start(%w[1 2 -r 3])[5]).to eq(3)
80
80
  end
81
81
  end
82
82
 
83
83
  describe "#class_option" do
84
84
  it "sets options class wise" do
85
- expect(MyCounter.start(["1", "2", "--third", "3"])[2]).to eq(3)
85
+ expect(MyCounter.start(%w[1 2 --third 3])[2]).to eq(3)
86
86
  end
87
87
 
88
88
  it "does not create an accessor for it" do
89
- expect(BrokenCounter.start(["1", "2", "--third", "3"])[3]).to be_false
89
+ expect(BrokenCounter.start(%w[1 2 --third 3])[3]).to be false
90
90
  end
91
91
  end
92
92
 
@@ -98,7 +98,7 @@ describe Thor::Base do
98
98
  end
99
99
 
100
100
  describe "#remove_argument" do
101
- it "removes previous defined arguments from class" do
101
+ it "removes previously defined arguments from class" do
102
102
  expect(ClearCounter.arguments).to be_empty
103
103
  end
104
104
 
@@ -110,7 +110,7 @@ describe Thor::Base do
110
110
 
111
111
  describe "#remove_class_option" do
112
112
  it "removes previous defined class option" do
113
- expect(ClearCounter.class_options[:third]).to be_nil
113
+ expect(ClearCounter.class_options[:third]).to be nil
114
114
  end
115
115
  end
116
116
 
@@ -119,7 +119,7 @@ describe Thor::Base do
119
119
  @content = capture(:stdout) { MyCounter.help(Thor::Base.shell.new) }
120
120
  end
121
121
 
122
- it "shows options description" do
122
+ it "shows option's description" do
123
123
  expect(@content).to match(/# The third argument/)
124
124
  end
125
125
 
@@ -127,7 +127,7 @@ describe Thor::Base do
127
127
  expect(@content).to match(/\[\-\-third=THREE\]/)
128
128
  end
129
129
 
130
- it "shows default values below description" do
130
+ it "shows default values below descriptions" do
131
131
  expect(@content).to match(/# Default: 3/)
132
132
  end
133
133
 
@@ -137,13 +137,13 @@ describe Thor::Base do
137
137
  expect(@content).to match(/\-p, \[\-\-pretend\]/)
138
138
  end
139
139
 
140
- it "use padding in options that does not have aliases" do
140
+ it "use padding in options that do not have aliases" do
141
141
  expect(@content).to match(/^ -t, \[--third/)
142
142
  expect(@content).to match(/^ \[--fourth/)
143
143
  end
144
144
 
145
145
  it "allows extra options to be given" do
146
- hash = { "Foo" => B.class_options.values }
146
+ hash = {"Foo" => B.class_options.values}
147
147
 
148
148
  content = capture(:stdout) { MyCounter.send(:class_options_help, Thor::Base.shell.new, hash) }
149
149
  expect(content).to match(/Foo options\:/)
@@ -212,10 +212,10 @@ describe Thor::Base do
212
212
  end
213
213
 
214
214
  it "raises an error if a command with reserved word is defined" do
215
- expect {
215
+ expect do
216
216
  klass = Class.new(Thor::Group)
217
217
  klass.class_eval "def shell; end"
218
- }.to raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as command/)
218
+ end.to raise_error(RuntimeError, /"shell" is a Thor reserved word and cannot be defined as command/)
219
219
  end
220
220
  end
221
221
 
@@ -244,48 +244,55 @@ describe Thor::Base do
244
244
  end
245
245
 
246
246
  describe "#start" do
247
- it "raises an error instead of rescueing if THOR_DEBUG=1 is given" do
247
+ it "raises an error instead of rescuing if THOR_DEBUG=1 is given" do
248
248
  begin
249
- ENV["THOR_DEBUG"] = 1
250
- expect {
251
- MyScript.start ["what", "--debug"]
252
- }.to raise_error(Thor::UndefinedcommandError, 'Could not find command "what" in "my_script" namespace.')
253
- rescue
249
+ ENV["THOR_DEBUG"] = "1"
250
+
251
+ expect do
252
+ MyScript.start %w[what --debug]
253
+ end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
254
+ ensure
254
255
  ENV["THOR_DEBUG"] = nil
255
256
  end
256
257
  end
257
258
 
259
+ it "raises an error instead of rescuing if :debug option is given" do
260
+ expect do
261
+ MyScript.start %w[what], :debug => true
262
+ end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
263
+ end
264
+
258
265
  it "does not steal args" do
259
- args = ["foo", "bar", "--force", "true"]
266
+ args = %w[foo bar --force true]
260
267
  MyScript.start(args)
261
- expect(args).to eq(["foo", "bar", "--force", "true"])
268
+ expect(args).to eq(%w[foo bar --force true])
262
269
  end
263
270
 
264
271
  it "checks unknown options" do
265
- expect(capture(:stderr) {
266
- MyScript.start(["foo", "bar", "--force", "true", "--unknown", "baz"])
267
- }.strip).to eq("Unknown switches '--unknown'")
272
+ expect(capture(:stderr) do
273
+ MyScript.start(%w[foo bar --force true --unknown baz])
274
+ end.strip).to eq("Unknown switches '--unknown'")
268
275
  end
269
276
 
270
277
  it "checks unknown options except specified" do
271
- expect(capture(:stderr) {
272
- expect(MyScript.start(["with_optional", "NAME", "--omg", "--invalid"])).to eq(["NAME", {}, ["--omg", "--invalid"]])
273
- }.strip).to be_empty
278
+ expect(capture(:stderr) do
279
+ expect(MyScript.start(%w[with_optional NAME --omg --invalid])).to eq(["NAME", {}, %w[--omg --invalid]])
280
+ end.strip).to be_empty
274
281
  end
275
282
  end
276
283
 
277
284
  describe "attr_*" do
278
285
  it "does not add attr_reader as a command" do
279
- expect(capture(:stderr){ MyScript.start(["another_attribute"]) }).to match(/Could not find/)
286
+ expect(capture(:stderr) { MyScript.start(%w[another_attribute]) }).to match(/Could not find/)
280
287
  end
281
288
 
282
289
  it "does not add attr_writer as a command" do
283
- expect(capture(:stderr){ MyScript.start(["another_attribute=", "foo"]) }).to match(/Could not find/)
290
+ expect(capture(:stderr) { MyScript.start(%w[another_attribute= foo]) }).to match(/Could not find/)
284
291
  end
285
292
 
286
293
  it "does not add attr_accessor as a command" do
287
- expect(capture(:stderr){ MyScript.start(["some_attribute"]) }).to match(/Could not find/)
288
- expect(capture(:stderr){ MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
294
+ expect(capture(:stderr) { MyScript.start(["some_attribute"]) }).to match(/Could not find/)
295
+ expect(capture(:stderr) { MyScript.start(["some_attribute=", "foo"]) }).to match(/Could not find/)
289
296
  end
290
297
  end
291
298
  end