puppet-module 0.3.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.
- data/CHANGES.markdown +91 -0
- data/LICENSE +17 -0
- data/README.markdown +221 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/bin/puppet-module +7 -0
- data/lib/puppet/module/tool.rb +124 -0
- data/lib/puppet/module/tool/applications.rb +18 -0
- data/lib/puppet/module/tool/applications/application.rb +83 -0
- data/lib/puppet/module/tool/applications/builder.rb +88 -0
- data/lib/puppet/module/tool/applications/checksummer.rb +38 -0
- data/lib/puppet/module/tool/applications/cleaner.rb +14 -0
- data/lib/puppet/module/tool/applications/freezer.rb +20 -0
- data/lib/puppet/module/tool/applications/generator.rb +117 -0
- data/lib/puppet/module/tool/applications/installer.rb +83 -0
- data/lib/puppet/module/tool/applications/registrar.rb +34 -0
- data/lib/puppet/module/tool/applications/releaser.rb +48 -0
- data/lib/puppet/module/tool/applications/searcher.rb +34 -0
- data/lib/puppet/module/tool/applications/unpacker.rb +69 -0
- data/lib/puppet/module/tool/applications/unreleaser.rb +42 -0
- data/lib/puppet/module/tool/cache.rb +56 -0
- data/lib/puppet/module/tool/checksums.rb +52 -0
- data/lib/puppet/module/tool/cli.rb +127 -0
- data/lib/puppet/module/tool/contents_description.rb +84 -0
- data/lib/puppet/module/tool/dependency.rb +26 -0
- data/lib/puppet/module/tool/metadata.rb +80 -0
- data/lib/puppet/module/tool/modulefile.rb +47 -0
- data/lib/puppet/module/tool/repository.rb +74 -0
- data/lib/puppet/module/tool/skeleton.rb +39 -0
- data/lib/puppet/module/tool/utils.rb +9 -0
- data/lib/puppet/module/tool/utils/interrogation.rb +39 -0
- data/lib/puppet/module/tool/utils/settings.rb +36 -0
- data/lib/puppet/module/tool/utils/uri.rb +16 -0
- data/spec/fixtures/releases/jamtur01-apache/Modulefile +2 -0
- data/spec/fixtures/releases/jamtur01-apache/files/httpd +24 -0
- data/spec/fixtures/releases/jamtur01-apache/files/test.vhost +18 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +21 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/type/a2mod.rb +12 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/dev.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/init.pp +34 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/params.pp +17 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/php.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/ssl.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/vhost.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -0
- data/spec/fixtures/releases/jamtur01-apache/templates/vhost-default.conf.erb +20 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/apache.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/dev.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/init.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/php.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/ssl.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/vhost.pp +2 -0
- data/spec/integration/cli_spec.rb +373 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/output_support.rb +19 -0
- data/spec/support/stub_http_support.rb +14 -0
- data/spec/support/testdir_support.rb +26 -0
- data/spec/unit/application_spec.rb +25 -0
- data/spec/unit/repository_spec.rb +51 -0
- data/templates/generator/Modulefile.erb +5 -0
- data/templates/generator/README.erb +3 -0
- data/templates/generator/files/README.markdown +22 -0
- data/templates/generator/lib/puppet/facter/README.markdown +22 -0
- data/templates/generator/lib/puppet/parser/functions/README.markdown +17 -0
- data/templates/generator/lib/puppet/provider/README.markdown +14 -0
- data/templates/generator/lib/puppet/type/README.markdown +14 -0
- data/templates/generator/manifests/README.markdown +28 -0
- data/templates/generator/manifests/init.pp.erb +17 -0
- data/templates/generator/metadata.json +12 -0
- data/templates/generator/spec/README.markdown +7 -0
- data/templates/generator/spec/spec.opts +6 -0
- data/templates/generator/spec/spec_helper.rb +18 -0
- data/templates/generator/spec/unit/puppet/provider/README.markdown +4 -0
- data/templates/generator/spec/unit/puppet/type/README.markdown +4 -0
- data/templates/generator/templates/README.markdown +23 -0
- data/templates/generator/tests/init.pp.erb +1 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/returning.rb +23 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/tap.rb +39 -0
- data/vendor/multipart-post-1.0/Manifest.txt +9 -0
- data/vendor/multipart-post-1.0/README.txt +61 -0
- data/vendor/multipart-post-1.0/Rakefile +21 -0
- data/vendor/multipart-post-1.0/lib/composite_io.rb +89 -0
- data/vendor/multipart-post-1.0/lib/multipartable.rb +13 -0
- data/vendor/multipart-post-1.0/lib/net/http/post/multipart.rb +27 -0
- data/vendor/multipart-post-1.0/lib/parts.rb +66 -0
- data/vendor/multipart-post-1.0/test/net/http/post/test_multipart.rb +55 -0
- data/vendor/multipart-post-1.0/test/test_composite_io.rb +50 -0
- data/vendor/thor-852190ae/CHANGELOG.rdoc +89 -0
- data/vendor/thor-852190ae/LICENSE +20 -0
- data/vendor/thor-852190ae/README.rdoc +297 -0
- data/vendor/thor-852190ae/REVISION +1 -0
- data/vendor/thor-852190ae/Thorfile +69 -0
- data/vendor/thor-852190ae/bin/rake2thor +86 -0
- data/vendor/thor-852190ae/bin/thor +6 -0
- data/vendor/thor-852190ae/lib/thor.rb +244 -0
- data/vendor/thor-852190ae/lib/thor/actions.rb +275 -0
- data/vendor/thor-852190ae/lib/thor/actions/create_file.rb +103 -0
- data/vendor/thor-852190ae/lib/thor/actions/directory.rb +91 -0
- data/vendor/thor-852190ae/lib/thor/actions/empty_directory.rb +134 -0
- data/vendor/thor-852190ae/lib/thor/actions/file_manipulation.rb +223 -0
- data/vendor/thor-852190ae/lib/thor/actions/inject_into_file.rb +104 -0
- data/vendor/thor-852190ae/lib/thor/base.rb +540 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/vendor/thor-852190ae/lib/thor/error.rb +30 -0
- data/vendor/thor-852190ae/lib/thor/group.rb +271 -0
- data/vendor/thor-852190ae/lib/thor/invocation.rb +180 -0
- data/vendor/thor-852190ae/lib/thor/parser.rb +4 -0
- data/vendor/thor-852190ae/lib/thor/parser/argument.rb +67 -0
- data/vendor/thor-852190ae/lib/thor/parser/arguments.rb +150 -0
- data/vendor/thor-852190ae/lib/thor/parser/option.rb +128 -0
- data/vendor/thor-852190ae/lib/thor/parser/options.rb +169 -0
- data/vendor/thor-852190ae/lib/thor/rake_compat.rb +66 -0
- data/vendor/thor-852190ae/lib/thor/runner.rb +314 -0
- data/vendor/thor-852190ae/lib/thor/shell.rb +83 -0
- data/vendor/thor-852190ae/lib/thor/shell/basic.rb +239 -0
- data/vendor/thor-852190ae/lib/thor/shell/color.rb +108 -0
- data/vendor/thor-852190ae/lib/thor/task.rb +102 -0
- data/vendor/thor-852190ae/lib/thor/util.rb +230 -0
- data/vendor/thor-852190ae/lib/thor/version.rb +3 -0
- data/vendor/thor-852190ae/spec/actions/create_file_spec.rb +170 -0
- data/vendor/thor-852190ae/spec/actions/directory_spec.rb +131 -0
- data/vendor/thor-852190ae/spec/actions/empty_directory_spec.rb +91 -0
- data/vendor/thor-852190ae/spec/actions/file_manipulation_spec.rb +271 -0
- data/vendor/thor-852190ae/spec/actions/inject_into_file_spec.rb +135 -0
- data/vendor/thor-852190ae/spec/actions_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/base_spec.rb +263 -0
- data/vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
- data/vendor/thor-852190ae/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/vendor/thor-852190ae/spec/fixtures/application.rb +2 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/execute.rb +6 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/main.thor +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/README +3 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/config.rb +1 -0
- data/vendor/thor-852190ae/spec/fixtures/group.thor +83 -0
- data/vendor/thor-852190ae/spec/fixtures/invoke.thor +112 -0
- data/vendor/thor-852190ae/spec/fixtures/script.thor +140 -0
- data/vendor/thor-852190ae/spec/fixtures/task.thor +10 -0
- data/vendor/thor-852190ae/spec/group_spec.rb +171 -0
- data/vendor/thor-852190ae/spec/invocation_spec.rb +107 -0
- data/vendor/thor-852190ae/spec/parser/argument_spec.rb +47 -0
- data/vendor/thor-852190ae/spec/parser/arguments_spec.rb +64 -0
- data/vendor/thor-852190ae/spec/parser/option_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/parser/options_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/rake_compat_spec.rb +68 -0
- data/vendor/thor-852190ae/spec/runner_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/shell/basic_spec.rb +205 -0
- data/vendor/thor-852190ae/spec/shell/color_spec.rb +41 -0
- data/vendor/thor-852190ae/spec/shell_spec.rb +34 -0
- data/vendor/thor-852190ae/spec/spec.opts +1 -0
- data/vendor/thor-852190ae/spec/spec_helper.rb +54 -0
- data/vendor/thor-852190ae/spec/task_spec.rb +69 -0
- data/vendor/thor-852190ae/spec/thor_spec.rb +237 -0
- data/vendor/thor-852190ae/spec/util_spec.rb +167 -0
- data/vendor/thor-852190ae/thor.gemspec +120 -0
- metadata +229 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
require 'thor/parser'
|
|
3
|
+
|
|
4
|
+
describe Thor::Options do
|
|
5
|
+
def create(opts, defaults={})
|
|
6
|
+
opts.each do |key, value|
|
|
7
|
+
opts[key] = Thor::Option.parse(key, value) unless value.is_a?(Thor::Option)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
@opt = Thor::Options.new(opts, defaults)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def parse(*args)
|
|
14
|
+
@opt.parse(args.flatten)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def check_unknown!
|
|
18
|
+
@opt.check_unknown!
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "#to_switches" do
|
|
22
|
+
it "turns true values into a flag" do
|
|
23
|
+
Thor::Options.to_switches(:color => true).must == "--color"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "ignores nil" do
|
|
27
|
+
Thor::Options.to_switches(:color => nil).must == ""
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "ignores false" do
|
|
31
|
+
Thor::Options.to_switches(:color => false).must == ""
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "writes --name value for anything else" do
|
|
35
|
+
Thor::Options.to_switches(:format => "specdoc").must == '--format "specdoc"'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "joins several values" do
|
|
39
|
+
switches = Thor::Options.to_switches(:color => true, :foo => "bar").split(' ').sort
|
|
40
|
+
switches.must == ['"bar"', "--color", "--foo"]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "accepts arrays" do
|
|
44
|
+
Thor::Options.to_switches(:count => [1,2,3]).must == "--count 1 2 3"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "accepts hashes" do
|
|
48
|
+
Thor::Options.to_switches(:count => {:a => :b}).must == "--count a:b"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "#parse" do
|
|
53
|
+
it "allows multiple aliases for a given switch" do
|
|
54
|
+
create ["--foo", "--bar", "--baz"] => :string
|
|
55
|
+
parse("--foo", "12")["foo"].must == "12"
|
|
56
|
+
parse("--bar", "12")["foo"].must == "12"
|
|
57
|
+
parse("--baz", "12")["foo"].must == "12"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "allows custom short names" do
|
|
61
|
+
create "-f" => :string
|
|
62
|
+
parse("-f", "12").must == {"f" => "12"}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "allows custom short-name aliases" do
|
|
66
|
+
create ["--bar", "-f"] => :string
|
|
67
|
+
parse("-f", "12").must == {"bar" => "12"}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "accepts conjoined short switches" do
|
|
71
|
+
create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => true
|
|
72
|
+
opts = parse("-fba")
|
|
73
|
+
opts["foo"].must be_true
|
|
74
|
+
opts["bar"].must be_true
|
|
75
|
+
opts["app"].must be_true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "accepts conjoined short switches with input" do
|
|
79
|
+
create ["--foo", "-f"] => true, ["--bar", "-b"] => true, ["--app", "-a"] => :required
|
|
80
|
+
opts = parse "-fba", "12"
|
|
81
|
+
opts["foo"].must be_true
|
|
82
|
+
opts["bar"].must be_true
|
|
83
|
+
opts["app"].must == "12"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "returns the default value if none is provided" do
|
|
87
|
+
create :foo => "baz", :bar => :required
|
|
88
|
+
parse("--bar", "boom")["foo"].must == "baz"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "returns the default value from defaults hash to required arguments" do
|
|
92
|
+
create Hash[:bar => :required], Hash[:bar => "baz"]
|
|
93
|
+
parse["bar"].must == "baz"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "gives higher priority to defaults given in the hash" do
|
|
97
|
+
create Hash[:bar => true], Hash[:bar => false]
|
|
98
|
+
parse["bar"].must == false
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "raises an error for unknown switches" do
|
|
102
|
+
create :foo => "baz", :bar => :required
|
|
103
|
+
parse("--bar", "baz", "--baz", "unknown")
|
|
104
|
+
lambda { check_unknown! }.must raise_error(Thor::UnknownArgumentError, "Unknown switches '--baz'")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "skips leading non-switches" do
|
|
108
|
+
create(:foo => "baz")
|
|
109
|
+
|
|
110
|
+
parse("asdf", "--foo", "bar").must == {"foo" => "bar"}
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "correctly recognizes things that look kind of like options, but aren't, as not options" do
|
|
114
|
+
create(:foo => "baz")
|
|
115
|
+
parse("--asdf---asdf", "baz", "--foo", "--asdf---dsf--asdf").must == {"foo" => "--asdf---dsf--asdf"}
|
|
116
|
+
check_unknown!
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "with no input" do
|
|
120
|
+
it "and no switches returns an empty hash" do
|
|
121
|
+
create({})
|
|
122
|
+
parse.must == {}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "and several switches returns an empty hash" do
|
|
126
|
+
create "--foo" => :boolean, "--bar" => :string
|
|
127
|
+
parse.must == {}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "and a required switch raises an error" do
|
|
131
|
+
create "--foo" => :required
|
|
132
|
+
lambda { parse }.must raise_error(Thor::RequiredArgumentMissingError, "No value provided for required options '--foo'")
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe "with one required and one optional switch" do
|
|
137
|
+
before :each do
|
|
138
|
+
create "--foo" => :required, "--bar" => :boolean
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "raises an error if the required switch has no argument" do
|
|
142
|
+
lambda { parse("--foo") }.must raise_error(Thor::MalformattedArgumentError)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "raises an error if the required switch isn't given" do
|
|
146
|
+
lambda { parse("--bar") }.must raise_error(Thor::RequiredArgumentMissingError)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "raises an error if the required switch is set to nil" do
|
|
150
|
+
lambda { parse("--no-foo") }.must raise_error(Thor::RequiredArgumentMissingError)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "does not raises an error if the required option has a default value" do
|
|
154
|
+
create :foo => Thor::Option.new("foo", nil, true, :string, "baz"), :bar => :boolean
|
|
155
|
+
lambda { parse("--bar") }.must_not raise_error
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
describe "with :string type" do
|
|
160
|
+
before(:each) do
|
|
161
|
+
create ["--foo", "-f"] => :required
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "accepts a switch <value> assignment" do
|
|
165
|
+
parse("--foo", "12")["foo"].must == "12"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "accepts a switch=<value> assignment" do
|
|
169
|
+
parse("-f=12")["foo"].must == "12"
|
|
170
|
+
parse("--foo=12")["foo"].must == "12"
|
|
171
|
+
parse("--foo=bar=baz")["foo"].must == "bar=baz"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "accepts a --no-switch format" do
|
|
175
|
+
create "--foo" => "bar"
|
|
176
|
+
parse("--no-foo")["foo"].must be_nil
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "accepts a --switch format on non required types" do
|
|
180
|
+
create "--foo" => :string
|
|
181
|
+
parse("--foo")["foo"].must == "foo"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it "accepts a --switch format on non required types with default values" do
|
|
185
|
+
create "--baz" => :string, "--foo" => "bar"
|
|
186
|
+
parse("--baz", "bang", "--foo")["foo"].must == "bar"
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it "overwrites earlier values with later values" do
|
|
190
|
+
parse("--foo=bar", "--foo", "12")["foo"].must == "12"
|
|
191
|
+
parse("--foo", "12", "--foo", "13")["foo"].must == "13"
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
describe "with :boolean type" do
|
|
196
|
+
before(:each) do
|
|
197
|
+
create "--foo" => false
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "accepts --opt assignment" do
|
|
201
|
+
parse("--foo")["foo"].must == true
|
|
202
|
+
parse("--foo", "--bar")["foo"].must == true
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it "accepts --opt=value assignment" do
|
|
206
|
+
parse("--foo=true")["foo"].must == true
|
|
207
|
+
parse("--foo=false")["foo"].must == false
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it "accepts --[no-]opt variant, setting false for value" do
|
|
211
|
+
parse("--no-foo")["foo"].must == false
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "accepts --[skip-]opt variant, setting false for value" do
|
|
215
|
+
parse("--skip-foo")["foo"].must == false
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
|
|
219
|
+
create "--no-foo" => true
|
|
220
|
+
parse("--no-foo")["no-foo"].must == true
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
|
|
224
|
+
create "--skip-foo" => true
|
|
225
|
+
parse("--skip-foo")["skip-foo"].must == true
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "accepts inputs in the human name format" do
|
|
229
|
+
create :foo_bar => :boolean
|
|
230
|
+
parse("--foo-bar")["foo_bar"].must == true
|
|
231
|
+
parse("--no-foo-bar")["foo_bar"].must == false
|
|
232
|
+
parse("--skip-foo-bar")["foo_bar"].must == false
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
describe "with :hash type" do
|
|
237
|
+
before(:each) do
|
|
238
|
+
create "--attributes" => :hash
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it "accepts a switch=<value> assignment" do
|
|
242
|
+
parse("--attributes=name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "accepts a switch <value> assignment" do
|
|
246
|
+
parse("--attributes", "name:string", "age:integer")["attributes"].must == {"name" => "string", "age" => "integer"}
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "must not mix values with other switches" do
|
|
250
|
+
parse("--attributes", "name:string", "age:integer", "--baz", "cool")["attributes"].must == {"name" => "string", "age" => "integer"}
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
describe "with :array type" do
|
|
255
|
+
before(:each) do
|
|
256
|
+
create "--attributes" => :array
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "accepts a switch=<value> assignment" do
|
|
260
|
+
parse("--attributes=a", "b", "c")["attributes"].must == ["a", "b", "c"]
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "accepts a switch <value> assignment" do
|
|
264
|
+
parse("--attributes", "a", "b", "c")["attributes"].must == ["a", "b", "c"]
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it "must not mix values with other switches" do
|
|
268
|
+
parse("--attributes", "a", "b", "c", "--baz", "cool")["attributes"].must == ["a", "b", "c"]
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
describe "with :numeric type" do
|
|
273
|
+
before(:each) do
|
|
274
|
+
create "n" => :numeric, "m" => 5
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it "accepts a -nXY assignment" do
|
|
278
|
+
parse("-n12")["n"].must == 12
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
it "converts values to numeric types" do
|
|
282
|
+
parse("-n", "3", "-m", ".5").must == {"n" => 3, "m" => 0.5}
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it "raises error when value isn't numeric" do
|
|
286
|
+
lambda { parse("-n", "foo") }.must raise_error(Thor::MalformattedArgumentError,
|
|
287
|
+
"Expected numeric value for '-n'; got \"foo\"")
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
end
|
|
292
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require 'thor/rake_compat'
|
|
3
|
+
require 'rake/tasklib'
|
|
4
|
+
|
|
5
|
+
class RakeTask < Rake::TaskLib
|
|
6
|
+
def initialize
|
|
7
|
+
define
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def define
|
|
11
|
+
desc "Say it's cool"
|
|
12
|
+
task :cool do
|
|
13
|
+
puts "COOL"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
namespace :hiper_mega do
|
|
17
|
+
task :super do
|
|
18
|
+
puts "HIPER MEGA SUPER"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ThorTask < Thor
|
|
25
|
+
include Thor::RakeCompat
|
|
26
|
+
RakeTask.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe Thor::RakeCompat do
|
|
30
|
+
it "sets the rakefile application" do
|
|
31
|
+
["rake_compat_spec.rb", "Thorfile"].must include(Rake.application.rakefile)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "adds rake tasks to thor classes too" do
|
|
35
|
+
task = ThorTask.tasks["cool"]
|
|
36
|
+
task.must be
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "uses rake tasks descriptions on thor" do
|
|
40
|
+
ThorTask.tasks["cool"].description.must == "Say it's cool"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "gets usage from rake tasks name" do
|
|
44
|
+
ThorTask.tasks["cool"].usage.must == "cool"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "uses non namespaced name as description if non is available" do
|
|
48
|
+
ThorTask::HiperMega.tasks["super"].description.must == "super"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "converts namespaces to classes" do
|
|
52
|
+
ThorTask.const_get(:HiperMega).must == ThorTask::HiperMega
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "does not add tasks from higher namespaces in lowers namespaces" do
|
|
56
|
+
ThorTask.tasks["super"].must_not be
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "invoking the thor task invokes the rake task" do
|
|
60
|
+
capture(:stdout) do
|
|
61
|
+
ThorTask.start ["cool"]
|
|
62
|
+
end.must == "COOL\n"
|
|
63
|
+
|
|
64
|
+
capture(:stdout) do
|
|
65
|
+
ThorTask::HiperMega.start ["super"]
|
|
66
|
+
end.must == "HIPER MEGA SUPER\n"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
|
2
|
+
require 'thor/runner'
|
|
3
|
+
|
|
4
|
+
describe Thor::Runner do
|
|
5
|
+
describe "#help" do
|
|
6
|
+
it "shows information about Thor::Runner itself" do
|
|
7
|
+
capture(:stdout){ Thor::Runner.start(["help"]) }.must =~ /List the available thor tasks/
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "shows information about an specific Thor::Runner task" do
|
|
11
|
+
content = capture(:stdout){ Thor::Runner.start(["help", "list"]) }
|
|
12
|
+
content.must =~ /List the available thor tasks/
|
|
13
|
+
content.must_not =~ /help \[TASK\]/
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "shows information about a specific Thor class" do
|
|
17
|
+
content = capture(:stdout){ Thor::Runner.start(["help", "my_script"]) }
|
|
18
|
+
content.must =~ /zoo\s+# zoo around/m
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "shows information about an specific task from an specific Thor class" do
|
|
22
|
+
content = capture(:stdout){ Thor::Runner.start(["help", "my_script:zoo"]) }
|
|
23
|
+
content.must =~ /zoo around/
|
|
24
|
+
content.must_not =~ /help \[TASK\]/
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "shows information about a specific Thor group class" do
|
|
28
|
+
content = capture(:stdout){ Thor::Runner.start(["help", "my_counter"]) }
|
|
29
|
+
content.must =~ /my_counter N/
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "raises error if a class/task cannot be found" do
|
|
33
|
+
Thor::Runner.should_receive(:exit).with(1)
|
|
34
|
+
content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
|
|
35
|
+
content.strip.must == 'Could not find namespace or task "unknown".'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "#start" do
|
|
40
|
+
it "invokes a task from Thor::Runner" do
|
|
41
|
+
ARGV.replace ["list"]
|
|
42
|
+
capture(:stdout){ Thor::Runner.start }.must =~ /my_counter N/
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "invokes a task from a specific Thor class" do
|
|
46
|
+
ARGV.replace ["my_script:zoo"]
|
|
47
|
+
Thor::Runner.start.must be_true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "invokes the default task from a specific Thor class if none is specified" do
|
|
51
|
+
ARGV.replace ["my_script"]
|
|
52
|
+
Thor::Runner.start.must == "default task"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "forwads arguments to the invoked task" do
|
|
56
|
+
ARGV.replace ["my_script:animal", "horse"]
|
|
57
|
+
Thor::Runner.start.must == ["horse"]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "invokes tasks through shortcuts" do
|
|
61
|
+
ARGV.replace ["my_script", "-T", "horse"]
|
|
62
|
+
Thor::Runner.start.must == ["horse"]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "invokes a Thor::Group" do
|
|
66
|
+
ARGV.replace ["my_counter", "1", "2", "--third", "3"]
|
|
67
|
+
Thor::Runner.start.must == [1, 2, 3]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "raises an error if class/task can't be found" do
|
|
71
|
+
Thor::Runner.should_receive(:exit).with(1)
|
|
72
|
+
ARGV.replace ["unknown"]
|
|
73
|
+
content = capture(:stderr){ Thor::Runner.start }
|
|
74
|
+
content.strip.must == 'Could not find namespace or task "unknown".'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "does not swallow NoMethodErrors that occur inside the called method" do
|
|
78
|
+
ARGV.replace ["my_script:call_unexistent_method"]
|
|
79
|
+
lambda { Thor::Runner.start }.must raise_error(NoMethodError)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "does not swallow Thor::Group InvocationError" do
|
|
83
|
+
ARGV.replace ["whiny_generator"]
|
|
84
|
+
lambda { Thor::Runner.start }.must raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "does not swallow Thor InvocationError" do
|
|
88
|
+
ARGV.replace ["my_script:animal"]
|
|
89
|
+
content = capture(:stderr) { Thor::Runner.start }
|
|
90
|
+
content.strip.must == '"animal" was called incorrectly. Call as "my_script:animal TYPE".'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "tasks" do
|
|
95
|
+
before(:each) do
|
|
96
|
+
@location = "#{File.dirname(__FILE__)}/fixtures/task.thor"
|
|
97
|
+
@original_yaml = {
|
|
98
|
+
"random" => {
|
|
99
|
+
:location => @location,
|
|
100
|
+
:filename => "4a33b894ffce85d7b412fc1b36f88fe0",
|
|
101
|
+
:namespaces => ["amazing"]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
root_file = File.join(Thor::Util.thor_root, "thor.yml")
|
|
106
|
+
|
|
107
|
+
# Stub load and save to avoid thor.yaml from being overwritten
|
|
108
|
+
YAML.stub!(:load_file).and_return(@original_yaml)
|
|
109
|
+
File.stub!(:exists?).with(root_file).and_return(true)
|
|
110
|
+
File.stub!(:open).with(root_file, "w")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "list" do
|
|
114
|
+
it "gives a list of the available tasks" do
|
|
115
|
+
ARGV.replace ["list"]
|
|
116
|
+
content = capture(:stdout) { Thor::Runner.start }
|
|
117
|
+
content.must =~ /amazing:describe NAME\s+# say that someone is amazing/m
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "gives a list of the available Thor::Group classes" do
|
|
121
|
+
ARGV.replace ["list"]
|
|
122
|
+
capture(:stdout) { Thor::Runner.start }.must =~ /my_counter N/
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "can filter a list of the available tasks by --group" do
|
|
126
|
+
ARGV.replace ["list", "--group", "standard"]
|
|
127
|
+
capture(:stdout) { Thor::Runner.start }.must =~ /amazing:describe NAME/
|
|
128
|
+
ARGV.replace []
|
|
129
|
+
capture(:stdout) { Thor::Runner.start }.must_not =~ /my_script:animal TYPE/
|
|
130
|
+
ARGV.replace ["list", "--group", "script"]
|
|
131
|
+
capture(:stdout) { Thor::Runner.start }.must =~ /my_script:animal TYPE/
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "can skip all filters to show all tasks using --all" do
|
|
135
|
+
ARGV.replace ["list", "--all"]
|
|
136
|
+
content = capture(:stdout) { Thor::Runner.start }
|
|
137
|
+
content.must =~ /amazing:describe NAME/
|
|
138
|
+
content.must =~ /my_script:animal TYPE/
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "doesn't list superclass tasks in the subclass" do
|
|
142
|
+
ARGV.replace ["list"]
|
|
143
|
+
capture(:stdout) { Thor::Runner.start }.must_not =~ /amazing:help/
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "presents tasks in the default namespace with an empty namespace" do
|
|
147
|
+
ARGV.replace ["list"]
|
|
148
|
+
capture(:stdout) { Thor::Runner.start }.must =~ /^thor :test\s+# prints 'test'/m
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "runs tasks with an empty namespace from the default namespace" do
|
|
152
|
+
ARGV.replace [":test"]
|
|
153
|
+
capture(:stdout) { Thor::Runner.start }.must == "test\n"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe "uninstall" do
|
|
158
|
+
before(:each) do
|
|
159
|
+
path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
|
|
160
|
+
FileUtils.should_receive(:rm_rf).with(path)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "uninstalls existing thor modules" do
|
|
164
|
+
silence(:stdout) { Thor::Runner.start(["uninstall", "random"]) }
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
describe "installed" do
|
|
169
|
+
before(:each) do
|
|
170
|
+
Dir.should_receive(:[]).and_return([])
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "displays the modules installed in a pretty way" do
|
|
174
|
+
stdout = capture(:stdout) { Thor::Runner.start(["installed"]) }
|
|
175
|
+
stdout.must =~ /random\s*amazing/
|
|
176
|
+
stdout.must =~ /amazing:describe NAME\s+# say that someone is amazing/m
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "install/update" do
|
|
181
|
+
before(:each) do
|
|
182
|
+
FileUtils.stub!(:mkdir_p)
|
|
183
|
+
FileUtils.stub!(:touch)
|
|
184
|
+
$stdin.stub!(:gets).and_return("Y")
|
|
185
|
+
|
|
186
|
+
path = File.join(Thor::Util.thor_root, Digest::MD5.hexdigest(@location + "random"))
|
|
187
|
+
File.should_receive(:open).with(path, "w")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "updates existing thor files" do
|
|
191
|
+
path = File.join(Thor::Util.thor_root, @original_yaml["random"][:filename])
|
|
192
|
+
File.should_receive(:delete).with(path)
|
|
193
|
+
silence(:stdout) { Thor::Runner.start(["update", "random"]) }
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "installs thor files" do
|
|
197
|
+
ARGV.replace ["install", @location]
|
|
198
|
+
silence(:stdout) { Thor::Runner.start }
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|