thor 0.19.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/CONTRIBUTING.md +15 -0
  4. data/README.md +7 -1
  5. data/lib/thor.rb +31 -23
  6. data/lib/thor/actions.rb +21 -22
  7. data/lib/thor/actions/create_file.rb +1 -1
  8. data/lib/thor/actions/create_link.rb +1 -1
  9. data/lib/thor/actions/directory.rb +2 -2
  10. data/lib/thor/actions/empty_directory.rb +8 -8
  11. data/lib/thor/actions/file_manipulation.rb +23 -12
  12. data/lib/thor/actions/inject_into_file.rb +10 -14
  13. data/lib/thor/base.rb +33 -33
  14. data/lib/thor/command.rb +9 -9
  15. data/lib/thor/core_ext/hash_with_indifferent_access.rb +9 -1
  16. data/lib/thor/core_ext/io_binary_read.rb +7 -5
  17. data/lib/thor/core_ext/ordered_hash.rb +94 -63
  18. data/lib/thor/error.rb +3 -3
  19. data/lib/thor/group.rb +12 -12
  20. data/lib/thor/invocation.rb +4 -5
  21. data/lib/thor/parser/argument.rb +4 -7
  22. data/lib/thor/parser/arguments.rb +16 -16
  23. data/lib/thor/parser/option.rb +39 -19
  24. data/lib/thor/parser/options.rb +7 -5
  25. data/lib/thor/runner.rb +25 -25
  26. data/lib/thor/shell.rb +1 -1
  27. data/lib/thor/shell/basic.rb +41 -26
  28. data/lib/thor/shell/color.rb +1 -1
  29. data/lib/thor/shell/html.rb +4 -4
  30. data/lib/thor/util.rb +8 -7
  31. data/lib/thor/version.rb +1 -1
  32. data/thor.gemspec +6 -9
  33. metadata +6 -148
  34. data/Thorfile +0 -29
  35. data/spec/actions/create_file_spec.rb +0 -168
  36. data/spec/actions/create_link_spec.rb +0 -96
  37. data/spec/actions/directory_spec.rb +0 -169
  38. data/spec/actions/empty_directory_spec.rb +0 -129
  39. data/spec/actions/file_manipulation_spec.rb +0 -392
  40. data/spec/actions/inject_into_file_spec.rb +0 -135
  41. data/spec/actions_spec.rb +0 -331
  42. data/spec/base_spec.rb +0 -298
  43. data/spec/command_spec.rb +0 -79
  44. data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
  45. data/spec/core_ext/ordered_hash_spec.rb +0 -115
  46. data/spec/exit_condition_spec.rb +0 -19
  47. data/spec/fixtures/application.rb +0 -2
  48. data/spec/fixtures/app{1}/README +0 -3
  49. data/spec/fixtures/bundle/execute.rb +0 -6
  50. data/spec/fixtures/bundle/main.thor +0 -1
  51. data/spec/fixtures/command.thor +0 -10
  52. data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
  53. data/spec/fixtures/doc/COMMENTER +0 -11
  54. data/spec/fixtures/doc/README +0 -3
  55. data/spec/fixtures/doc/block_helper.rb +0 -3
  56. data/spec/fixtures/doc/config.rb +0 -1
  57. data/spec/fixtures/doc/config.yaml.tt +0 -1
  58. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
  59. data/spec/fixtures/enum.thor +0 -10
  60. data/spec/fixtures/group.thor +0 -128
  61. data/spec/fixtures/invoke.thor +0 -131
  62. data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
  63. data/spec/fixtures/preserve/script.sh +0 -3
  64. data/spec/fixtures/script.thor +0 -220
  65. data/spec/fixtures/subcommand.thor +0 -17
  66. data/spec/group_spec.rb +0 -222
  67. data/spec/helper.rb +0 -80
  68. data/spec/invocation_spec.rb +0 -120
  69. data/spec/line_editor/basic_spec.rb +0 -28
  70. data/spec/line_editor/readline_spec.rb +0 -69
  71. data/spec/line_editor_spec.rb +0 -43
  72. data/spec/parser/argument_spec.rb +0 -53
  73. data/spec/parser/arguments_spec.rb +0 -66
  74. data/spec/parser/option_spec.rb +0 -210
  75. data/spec/parser/options_spec.rb +0 -414
  76. data/spec/quality_spec.rb +0 -75
  77. data/spec/rake_compat_spec.rb +0 -72
  78. data/spec/register_spec.rb +0 -227
  79. data/spec/runner_spec.rb +0 -246
  80. data/spec/sandbox/application.rb +0 -2
  81. data/spec/sandbox/app{1}/README +0 -3
  82. data/spec/sandbox/bundle/execute.rb +0 -6
  83. data/spec/sandbox/bundle/main.thor +0 -1
  84. data/spec/sandbox/command.thor +0 -10
  85. data/spec/sandbox/doc/%file_name%.rb.tt +0 -1
  86. data/spec/sandbox/doc/COMMENTER +0 -11
  87. data/spec/sandbox/doc/README +0 -3
  88. data/spec/sandbox/doc/block_helper.rb +0 -3
  89. data/spec/sandbox/doc/config.rb +0 -1
  90. data/spec/sandbox/doc/config.yaml.tt +0 -1
  91. data/spec/sandbox/doc/excluding/%file_name%.rb.tt +0 -1
  92. data/spec/sandbox/enum.thor +0 -10
  93. data/spec/sandbox/group.thor +0 -128
  94. data/spec/sandbox/invoke.thor +0 -131
  95. data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
  96. data/spec/sandbox/preserve/script.sh +0 -3
  97. data/spec/sandbox/script.thor +0 -220
  98. data/spec/sandbox/subcommand.thor +0 -17
  99. data/spec/shell/basic_spec.rb +0 -337
  100. data/spec/shell/color_spec.rb +0 -119
  101. data/spec/shell/html_spec.rb +0 -31
  102. data/spec/shell_spec.rb +0 -47
  103. data/spec/subcommand_spec.rb +0 -48
  104. data/spec/thor_spec.rb +0 -505
  105. data/spec/util_spec.rb +0 -196
@@ -1,196 +0,0 @@
1
- require "helper"
2
-
3
- module Thor::Util
4
- def self.clear_user_home!
5
- @@user_home = nil
6
- end
7
- end
8
-
9
- describe Thor::Util do
10
- describe "#find_by_namespace" do
11
- it "returns 'default' if no namespace is given" do
12
- expect(Thor::Util.find_by_namespace("")).to eq(Scripts::MyDefaults)
13
- end
14
-
15
- it "adds 'default' if namespace starts with :" do
16
- expect(Thor::Util.find_by_namespace(":child")).to eq(Scripts::ChildDefault)
17
- end
18
-
19
- it "returns nil if the namespace can't be found" do
20
- expect(Thor::Util.find_by_namespace("thor:core_ext:ordered_hash")).to be nil
21
- end
22
-
23
- it "returns a class if it matches the namespace" do
24
- expect(Thor::Util.find_by_namespace("app:broken:counter")).to eq(BrokenCounter)
25
- end
26
-
27
- it "matches classes default namespace" do
28
- expect(Thor::Util.find_by_namespace("scripts:my_script")).to eq(Scripts::MyScript)
29
- end
30
- end
31
-
32
- describe "#namespace_from_thor_class" do
33
- it "replaces constant nesting with command namespacing" do
34
- expect(Thor::Util.namespace_from_thor_class("Foo::Bar::Baz")).to eq("foo:bar:baz")
35
- end
36
-
37
- it "snake-cases component strings" do
38
- expect(Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom")).to eq("foo_bar:bar_baz:baz_boom")
39
- end
40
-
41
- it "accepts class and module objects" do
42
- expect(Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash)).to eq("thor:core_ext:ordered_hash")
43
- expect(Thor::Util.namespace_from_thor_class(Thor::Util)).to eq("thor:util")
44
- end
45
-
46
- it "removes Thor::Sandbox namespace" do
47
- expect(Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package")).to eq("package")
48
- end
49
- end
50
-
51
- describe "#namespaces_in_content" do
52
- it "returns an array of names of constants defined in the string" do
53
- list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end")
54
- expect(list).to include("foo:bar")
55
- expect(list).not_to include("bar:bat")
56
- end
57
-
58
- it "doesn't put the newly-defined constants in the enclosing namespace" do
59
- Thor::Util.namespaces_in_content("class Blat; end")
60
- expect(defined?(Blat)).not_to be
61
- expect(defined?(Thor::Sandbox::Blat)).to be
62
- end
63
- end
64
-
65
- describe "#snake_case" do
66
- it "preserves no-cap strings" do
67
- expect(Thor::Util.snake_case("foo")).to eq("foo")
68
- expect(Thor::Util.snake_case("foo_bar")).to eq("foo_bar")
69
- end
70
-
71
- it "downcases all-caps strings" do
72
- expect(Thor::Util.snake_case("FOO")).to eq("foo")
73
- expect(Thor::Util.snake_case("FOO_BAR")).to eq("foo_bar")
74
- end
75
-
76
- it "downcases initial-cap strings" do
77
- expect(Thor::Util.snake_case("Foo")).to eq("foo")
78
- end
79
-
80
- it "replaces camel-casing with underscores" do
81
- expect(Thor::Util.snake_case("FooBarBaz")).to eq("foo_bar_baz")
82
- expect(Thor::Util.snake_case("Foo_BarBaz")).to eq("foo_bar_baz")
83
- end
84
-
85
- it "places underscores between multiple capitals" do
86
- expect(Thor::Util.snake_case("ABClass")).to eq("a_b_class")
87
- end
88
- end
89
-
90
- describe "#find_class_and_command_by_namespace" do
91
- it "returns a Thor::Group class if full namespace matches" do
92
- expect(Thor::Util.find_class_and_command_by_namespace("my_counter")).to eq([MyCounter, nil])
93
- end
94
-
95
- it "returns a Thor class if full namespace matches" do
96
- expect(Thor::Util.find_class_and_command_by_namespace("thor")).to eq([Thor, nil])
97
- end
98
-
99
- it "returns a Thor class and the command name" do
100
- expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
101
- end
102
-
103
- it "falls back in the namespace:command look up even if a full namespace does not match" do
104
- Thor.const_set(:Help, Module.new)
105
- expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
106
- Thor.send :remove_const, :Help
107
- end
108
-
109
- it "falls back on the default namespace class if nothing else matches" do
110
- expect(Thor::Util.find_class_and_command_by_namespace("test")).to eq([Scripts::MyDefaults, "test"])
111
- end
112
- end
113
-
114
- describe "#thor_classes_in" do
115
- it "returns thor classes inside the given class" do
116
- expect(Thor::Util.thor_classes_in(MyScript)).to eq([MyScript::AnotherScript])
117
- expect(Thor::Util.thor_classes_in(MyScript::AnotherScript)).to be_empty
118
- end
119
- end
120
-
121
- describe "#user_home" do
122
- before do
123
- allow(ENV).to receive(:[])
124
- Thor::Util.clear_user_home!
125
- end
126
-
127
- it "returns the user path if no variable is set on the environment" do
128
- expect(Thor::Util.user_home).to eq(File.expand_path("~"))
129
- end
130
-
131
- it "returns the *nix system path if file cannot be expanded and separator does not exist" do
132
- expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
133
- previous_value = File::ALT_SEPARATOR
134
- capture(:stderr) { File.const_set(:ALT_SEPARATOR, false) } # rubocop:disable SymbolName
135
- expect(Thor::Util.user_home).to eq("/")
136
- capture(:stderr) { File.const_set(:ALT_SEPARATOR, previous_value) } # rubocop:disable SymbolName
137
- end
138
-
139
- it "returns the windows system path if file cannot be expanded and a separator exists" do
140
- expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
141
- previous_value = File::ALT_SEPARATOR
142
- capture(:stderr) { File.const_set(:ALT_SEPARATOR, true) } # rubocop:disable SymbolName
143
- expect(Thor::Util.user_home).to eq("C:/")
144
- capture(:stderr) { File.const_set(:ALT_SEPARATOR, previous_value) } # rubocop:disable SymbolName
145
- end
146
-
147
- it "returns HOME/.thor if set" do
148
- allow(ENV).to receive(:[]).with("HOME").and_return("/home/user/")
149
- expect(Thor::Util.user_home).to eq("/home/user/")
150
- end
151
-
152
- it "returns path with HOMEDRIVE and HOMEPATH if set" do
153
- allow(ENV).to receive(:[]).with("HOMEDRIVE").and_return("D:/")
154
- allow(ENV).to receive(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
155
- expect(Thor::Util.user_home).to eq("D:/Documents and Settings/James")
156
- end
157
-
158
- it "returns APPDATA/.thor if set" do
159
- allow(ENV).to receive(:[]).with("APPDATA").and_return("/home/user/")
160
- expect(Thor::Util.user_home).to eq("/home/user/")
161
- end
162
- end
163
-
164
- describe "#thor_root_glob" do
165
- before do
166
- allow(ENV).to receive(:[])
167
- Thor::Util.clear_user_home!
168
- end
169
-
170
- it "escapes globs in path" do
171
- allow(ENV).to receive(:[]).with("HOME").and_return("/home/user{1}/")
172
- expect(Dir).to receive(:[]).with('/home/user\\{1\\}/.thor/*').and_return([])
173
- expect(Thor::Util.thor_root_glob).to eq([])
174
- end
175
- end
176
-
177
- describe "#globs_for" do
178
- it "escapes globs in path" do
179
- expect(Thor::Util.globs_for("/home/apps{1}")).to eq([
180
- '/home/apps\\{1\\}/Thorfile',
181
- '/home/apps\\{1\\}/*.thor',
182
- '/home/apps\\{1\\}/tasks/*.thor',
183
- '/home/apps\\{1\\}/lib/tasks/*.thor'
184
- ])
185
- end
186
- end
187
-
188
- describe "#escape_globs" do
189
- it "escapes ? * { } [ ] glob characters" do
190
- expect(Thor::Util.escape_globs("apps?")).to eq('apps\\?')
191
- expect(Thor::Util.escape_globs("apps*")).to eq('apps\\*')
192
- expect(Thor::Util.escape_globs("apps {1}")).to eq('apps \\{1\\}')
193
- expect(Thor::Util.escape_globs("apps [1]")).to eq('apps \\[1\\]')
194
- end
195
- end
196
- end