groovenauts-thor 0.19.1 → 0.19.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -24
  3. data/groovenauts-thor.gemspec +1 -1
  4. data/lib/thor/base.rb +1 -1
  5. data/lib/thor/core_ext/ordered_hash.rb +63 -94
  6. data/lib/thor/parser/arguments.rb +1 -1
  7. data/lib/thor/parser/option.rb +0 -15
  8. data/lib/thor/version.rb +1 -1
  9. data/spec/actions/create_file_spec.rb +168 -0
  10. data/spec/actions/create_link_spec.rb +96 -0
  11. data/spec/actions/directory_spec.rb +169 -0
  12. data/spec/actions/empty_directory_spec.rb +129 -0
  13. data/spec/actions/file_manipulation_spec.rb +392 -0
  14. data/spec/actions/inject_into_file_spec.rb +135 -0
  15. data/spec/actions_spec.rb +331 -0
  16. data/spec/base_spec.rb +298 -0
  17. data/spec/command_spec.rb +79 -0
  18. data/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  19. data/spec/core_ext/ordered_hash_spec.rb +115 -0
  20. data/spec/exit_condition_spec.rb +19 -0
  21. data/spec/fixtures/application.rb +2 -0
  22. data/spec/fixtures/app{1}/README +3 -0
  23. data/spec/fixtures/bundle/execute.rb +6 -0
  24. data/spec/fixtures/bundle/main.thor +1 -0
  25. data/spec/fixtures/command.thor +10 -0
  26. data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  27. data/spec/fixtures/doc/COMMENTER +11 -0
  28. data/spec/fixtures/doc/README +3 -0
  29. data/spec/fixtures/doc/block_helper.rb +3 -0
  30. data/spec/fixtures/doc/config.rb +1 -0
  31. data/spec/fixtures/doc/config.yaml.tt +1 -0
  32. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  33. data/spec/fixtures/enum.thor +10 -0
  34. data/spec/fixtures/group.thor +128 -0
  35. data/spec/fixtures/invoke.thor +131 -0
  36. data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
  37. data/spec/fixtures/preserve/script.sh +3 -0
  38. data/spec/fixtures/script.thor +220 -0
  39. data/spec/fixtures/subcommand.thor +17 -0
  40. data/spec/group_spec.rb +222 -0
  41. data/spec/helper.rb +80 -0
  42. data/spec/invocation_spec.rb +120 -0
  43. data/spec/line_editor/basic_spec.rb +28 -0
  44. data/spec/line_editor/readline_spec.rb +69 -0
  45. data/spec/line_editor_spec.rb +43 -0
  46. data/spec/parser/argument_spec.rb +53 -0
  47. data/spec/parser/arguments_spec.rb +66 -0
  48. data/spec/parser/option_spec.rb +210 -0
  49. data/spec/parser/options_spec.rb +414 -0
  50. data/spec/quality_spec.rb +75 -0
  51. data/spec/rake_compat_spec.rb +72 -0
  52. data/spec/register_spec.rb +227 -0
  53. data/spec/runner_spec.rb +246 -0
  54. data/spec/sandbox/application.rb +2 -0
  55. data/spec/sandbox/app{1}/README +3 -0
  56. data/spec/sandbox/bundle/execute.rb +6 -0
  57. data/spec/sandbox/bundle/main.thor +1 -0
  58. data/spec/sandbox/command.thor +10 -0
  59. data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
  60. data/spec/sandbox/doc/COMMENTER +11 -0
  61. data/spec/sandbox/doc/README +3 -0
  62. data/spec/sandbox/doc/block_helper.rb +3 -0
  63. data/spec/sandbox/doc/config.rb +1 -0
  64. data/spec/sandbox/doc/config.yaml.tt +1 -0
  65. data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
  66. data/spec/sandbox/enum.thor +10 -0
  67. data/spec/sandbox/group.thor +128 -0
  68. data/spec/sandbox/invoke.thor +131 -0
  69. data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
  70. data/spec/sandbox/preserve/script.sh +3 -0
  71. data/spec/sandbox/script.thor +220 -0
  72. data/spec/sandbox/subcommand.thor +17 -0
  73. data/spec/shell/basic_spec.rb +337 -0
  74. data/spec/shell/color_spec.rb +119 -0
  75. data/spec/shell/html_spec.rb +31 -0
  76. data/spec/shell_spec.rb +47 -0
  77. data/spec/subcommand_spec.rb +71 -0
  78. data/spec/thor_spec.rb +505 -0
  79. data/spec/util_spec.rb +196 -0
  80. metadata +146 -4
data/spec/util_spec.rb ADDED
@@ -0,0 +1,196 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovenauts-thor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.19.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi Akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,77 @@ files:
69
69
  - lib/thor/shell/html.rb
70
70
  - lib/thor/util.rb
71
71
  - lib/thor/version.rb
72
+ - spec/actions/create_file_spec.rb
73
+ - spec/actions/create_link_spec.rb
74
+ - spec/actions/directory_spec.rb
75
+ - spec/actions/empty_directory_spec.rb
76
+ - spec/actions/file_manipulation_spec.rb
77
+ - spec/actions/inject_into_file_spec.rb
78
+ - spec/actions_spec.rb
79
+ - spec/base_spec.rb
80
+ - spec/command_spec.rb
81
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
82
+ - spec/core_ext/ordered_hash_spec.rb
83
+ - spec/exit_condition_spec.rb
84
+ - spec/fixtures/application.rb
85
+ - spec/fixtures/app{1}/README
86
+ - spec/fixtures/bundle/execute.rb
87
+ - spec/fixtures/bundle/main.thor
88
+ - spec/fixtures/command.thor
89
+ - spec/fixtures/doc/%file_name%.rb.tt
90
+ - spec/fixtures/doc/COMMENTER
91
+ - spec/fixtures/doc/README
92
+ - spec/fixtures/doc/block_helper.rb
93
+ - spec/fixtures/doc/config.rb
94
+ - spec/fixtures/doc/config.yaml.tt
95
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
96
+ - spec/fixtures/enum.thor
97
+ - spec/fixtures/group.thor
98
+ - spec/fixtures/invoke.thor
99
+ - spec/fixtures/path with spaces
100
+ - spec/fixtures/preserve/script.sh
101
+ - spec/fixtures/script.thor
102
+ - spec/fixtures/subcommand.thor
103
+ - spec/group_spec.rb
104
+ - spec/helper.rb
105
+ - spec/invocation_spec.rb
106
+ - spec/line_editor/basic_spec.rb
107
+ - spec/line_editor/readline_spec.rb
108
+ - spec/line_editor_spec.rb
109
+ - spec/parser/argument_spec.rb
110
+ - spec/parser/arguments_spec.rb
111
+ - spec/parser/option_spec.rb
112
+ - spec/parser/options_spec.rb
113
+ - spec/quality_spec.rb
114
+ - spec/rake_compat_spec.rb
115
+ - spec/register_spec.rb
116
+ - spec/runner_spec.rb
117
+ - spec/sandbox/application.rb
118
+ - spec/sandbox/app{1}/README
119
+ - spec/sandbox/bundle/execute.rb
120
+ - spec/sandbox/bundle/main.thor
121
+ - spec/sandbox/command.thor
122
+ - spec/sandbox/doc/%file_name%.rb.tt
123
+ - spec/sandbox/doc/COMMENTER
124
+ - spec/sandbox/doc/README
125
+ - spec/sandbox/doc/block_helper.rb
126
+ - spec/sandbox/doc/config.rb
127
+ - spec/sandbox/doc/config.yaml.tt
128
+ - spec/sandbox/doc/excluding/%file_name%.rb.tt
129
+ - spec/sandbox/enum.thor
130
+ - spec/sandbox/group.thor
131
+ - spec/sandbox/invoke.thor
132
+ - spec/sandbox/path with spaces
133
+ - spec/sandbox/preserve/script.sh
134
+ - spec/sandbox/script.thor
135
+ - spec/sandbox/subcommand.thor
136
+ - spec/shell/basic_spec.rb
137
+ - spec/shell/color_spec.rb
138
+ - spec/shell/html_spec.rb
139
+ - spec/shell_spec.rb
140
+ - spec/subcommand_spec.rb
141
+ - spec/thor_spec.rb
142
+ - spec/util_spec.rb
72
143
  homepage: https://github.com/groovenauts/thor
73
144
  licenses:
74
145
  - MIT
@@ -89,8 +160,79 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
160
  version: 1.3.5
90
161
  requirements: []
91
162
  rubyforge_project:
92
- rubygems_version: 2.2.2
163
+ rubygems_version: 2.4.5
93
164
  signing_key:
94
165
  specification_version: 4
95
166
  summary: Thor is a toolkit for building powerful command-line interfaces.
96
- test_files: []
167
+ test_files:
168
+ - spec/actions/create_file_spec.rb
169
+ - spec/actions/create_link_spec.rb
170
+ - spec/actions/directory_spec.rb
171
+ - spec/actions/empty_directory_spec.rb
172
+ - spec/actions/file_manipulation_spec.rb
173
+ - spec/actions/inject_into_file_spec.rb
174
+ - spec/actions_spec.rb
175
+ - spec/base_spec.rb
176
+ - spec/command_spec.rb
177
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
178
+ - spec/core_ext/ordered_hash_spec.rb
179
+ - spec/exit_condition_spec.rb
180
+ - spec/fixtures/application.rb
181
+ - spec/fixtures/app{1}/README
182
+ - spec/fixtures/bundle/execute.rb
183
+ - spec/fixtures/bundle/main.thor
184
+ - spec/fixtures/command.thor
185
+ - spec/fixtures/doc/%file_name%.rb.tt
186
+ - spec/fixtures/doc/block_helper.rb
187
+ - spec/fixtures/doc/COMMENTER
188
+ - spec/fixtures/doc/config.rb
189
+ - spec/fixtures/doc/config.yaml.tt
190
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
191
+ - spec/fixtures/doc/README
192
+ - spec/fixtures/enum.thor
193
+ - spec/fixtures/group.thor
194
+ - spec/fixtures/invoke.thor
195
+ - spec/fixtures/path with spaces
196
+ - spec/fixtures/preserve/script.sh
197
+ - spec/fixtures/script.thor
198
+ - spec/fixtures/subcommand.thor
199
+ - spec/group_spec.rb
200
+ - spec/helper.rb
201
+ - spec/invocation_spec.rb
202
+ - spec/line_editor/basic_spec.rb
203
+ - spec/line_editor/readline_spec.rb
204
+ - spec/line_editor_spec.rb
205
+ - spec/parser/argument_spec.rb
206
+ - spec/parser/arguments_spec.rb
207
+ - spec/parser/option_spec.rb
208
+ - spec/parser/options_spec.rb
209
+ - spec/quality_spec.rb
210
+ - spec/rake_compat_spec.rb
211
+ - spec/register_spec.rb
212
+ - spec/runner_spec.rb
213
+ - spec/sandbox/application.rb
214
+ - spec/sandbox/app{1}/README
215
+ - spec/sandbox/bundle/execute.rb
216
+ - spec/sandbox/bundle/main.thor
217
+ - spec/sandbox/command.thor
218
+ - spec/sandbox/doc/%file_name%.rb.tt
219
+ - spec/sandbox/doc/block_helper.rb
220
+ - spec/sandbox/doc/COMMENTER
221
+ - spec/sandbox/doc/config.rb
222
+ - spec/sandbox/doc/config.yaml.tt
223
+ - spec/sandbox/doc/excluding/%file_name%.rb.tt
224
+ - spec/sandbox/doc/README
225
+ - spec/sandbox/enum.thor
226
+ - spec/sandbox/group.thor
227
+ - spec/sandbox/invoke.thor
228
+ - spec/sandbox/path with spaces
229
+ - spec/sandbox/preserve/script.sh
230
+ - spec/sandbox/script.thor
231
+ - spec/sandbox/subcommand.thor
232
+ - spec/shell/basic_spec.rb
233
+ - spec/shell/color_spec.rb
234
+ - spec/shell/html_spec.rb
235
+ - spec/shell_spec.rb
236
+ - spec/subcommand_spec.rb
237
+ - spec/thor_spec.rb
238
+ - spec/util_spec.rb