thor 0.19.1 → 0.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +15 -0
- data/README.md +7 -1
- data/lib/thor.rb +31 -23
- data/lib/thor/actions.rb +21 -22
- data/lib/thor/actions/create_file.rb +1 -1
- data/lib/thor/actions/create_link.rb +1 -1
- data/lib/thor/actions/directory.rb +2 -2
- data/lib/thor/actions/empty_directory.rb +8 -8
- data/lib/thor/actions/file_manipulation.rb +23 -12
- data/lib/thor/actions/inject_into_file.rb +10 -14
- data/lib/thor/base.rb +33 -33
- data/lib/thor/command.rb +9 -9
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +9 -1
- data/lib/thor/core_ext/io_binary_read.rb +7 -5
- data/lib/thor/core_ext/ordered_hash.rb +94 -63
- data/lib/thor/error.rb +3 -3
- data/lib/thor/group.rb +12 -12
- data/lib/thor/invocation.rb +4 -5
- data/lib/thor/parser/argument.rb +4 -7
- data/lib/thor/parser/arguments.rb +16 -16
- data/lib/thor/parser/option.rb +39 -19
- data/lib/thor/parser/options.rb +7 -5
- data/lib/thor/runner.rb +25 -25
- data/lib/thor/shell.rb +1 -1
- data/lib/thor/shell/basic.rb +41 -26
- data/lib/thor/shell/color.rb +1 -1
- data/lib/thor/shell/html.rb +4 -4
- data/lib/thor/util.rb +8 -7
- data/lib/thor/version.rb +1 -1
- data/thor.gemspec +6 -9
- metadata +6 -148
- data/Thorfile +0 -29
- data/spec/actions/create_file_spec.rb +0 -168
- data/spec/actions/create_link_spec.rb +0 -96
- data/spec/actions/directory_spec.rb +0 -169
- data/spec/actions/empty_directory_spec.rb +0 -129
- data/spec/actions/file_manipulation_spec.rb +0 -392
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -331
- data/spec/base_spec.rb +0 -298
- data/spec/command_spec.rb +0 -79
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/exit_condition_spec.rb +0 -19
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/app{1}/README +0 -3
- data/spec/fixtures/bundle/execute.rb +0 -6
- data/spec/fixtures/bundle/main.thor +0 -1
- data/spec/fixtures/command.thor +0 -10
- data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/spec/fixtures/doc/COMMENTER +0 -11
- data/spec/fixtures/doc/README +0 -3
- data/spec/fixtures/doc/block_helper.rb +0 -3
- data/spec/fixtures/doc/config.rb +0 -1
- data/spec/fixtures/doc/config.yaml.tt +0 -1
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
- data/spec/fixtures/enum.thor +0 -10
- data/spec/fixtures/group.thor +0 -128
- data/spec/fixtures/invoke.thor +0 -131
- data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
- data/spec/fixtures/preserve/script.sh +0 -3
- data/spec/fixtures/script.thor +0 -220
- data/spec/fixtures/subcommand.thor +0 -17
- data/spec/group_spec.rb +0 -222
- data/spec/helper.rb +0 -80
- data/spec/invocation_spec.rb +0 -120
- data/spec/line_editor/basic_spec.rb +0 -28
- data/spec/line_editor/readline_spec.rb +0 -69
- data/spec/line_editor_spec.rb +0 -43
- data/spec/parser/argument_spec.rb +0 -53
- data/spec/parser/arguments_spec.rb +0 -66
- data/spec/parser/option_spec.rb +0 -210
- data/spec/parser/options_spec.rb +0 -414
- data/spec/quality_spec.rb +0 -75
- data/spec/rake_compat_spec.rb +0 -72
- data/spec/register_spec.rb +0 -227
- data/spec/runner_spec.rb +0 -246
- data/spec/sandbox/application.rb +0 -2
- data/spec/sandbox/app{1}/README +0 -3
- data/spec/sandbox/bundle/execute.rb +0 -6
- data/spec/sandbox/bundle/main.thor +0 -1
- data/spec/sandbox/command.thor +0 -10
- data/spec/sandbox/doc/%file_name%.rb.tt +0 -1
- data/spec/sandbox/doc/COMMENTER +0 -11
- data/spec/sandbox/doc/README +0 -3
- data/spec/sandbox/doc/block_helper.rb +0 -3
- data/spec/sandbox/doc/config.rb +0 -1
- data/spec/sandbox/doc/config.yaml.tt +0 -1
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +0 -1
- data/spec/sandbox/enum.thor +0 -10
- data/spec/sandbox/group.thor +0 -128
- data/spec/sandbox/invoke.thor +0 -131
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +0 -3
- data/spec/sandbox/script.thor +0 -220
- data/spec/sandbox/subcommand.thor +0 -17
- data/spec/shell/basic_spec.rb +0 -337
- data/spec/shell/color_spec.rb +0 -119
- data/spec/shell/html_spec.rb +0 -31
- data/spec/shell_spec.rb +0 -47
- data/spec/subcommand_spec.rb +0 -48
- data/spec/thor_spec.rb +0 -505
- data/spec/util_spec.rb +0 -196
data/spec/util_spec.rb
DELETED
@@ -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
|