acquia_toolbelt 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.ruby-version +1 -0
- data/Gemfile.lock +35 -0
- data/README.md +55 -27
- data/acquia_toolbelt.gemspec +2 -0
- data/bin/acquia +6 -565
- data/lib/acquia_toolbelt/cli.rb +102 -0
- data/lib/acquia_toolbelt/cli/api.rb +106 -0
- data/lib/acquia_toolbelt/cli/auth.rb +31 -0
- data/lib/acquia_toolbelt/cli/database.rb +208 -0
- data/lib/acquia_toolbelt/cli/deploy.rb +30 -0
- data/lib/acquia_toolbelt/cli/domain.rb +166 -0
- data/lib/acquia_toolbelt/cli/environment.rb +38 -0
- data/lib/acquia_toolbelt/cli/file.rb +23 -0
- data/lib/acquia_toolbelt/cli/server.rb +61 -0
- data/lib/acquia_toolbelt/cli/site.rb +28 -0
- data/lib/acquia_toolbelt/cli/ssh.rb +69 -0
- data/lib/acquia_toolbelt/cli/svn.rb +65 -0
- data/lib/acquia_toolbelt/cli/task.rb +71 -0
- data/lib/acquia_toolbelt/cli/ui.rb +29 -0
- data/lib/acquia_toolbelt/error.rb +4 -0
- data/lib/acquia_toolbelt/thor.rb +95 -0
- data/lib/acquia_toolbelt/version.rb +1 -1
- data/lib/vendor/thor/CHANGELOG.md +139 -0
- data/lib/vendor/thor/Gemfile +20 -0
- data/lib/vendor/thor/LICENSE.md +20 -0
- data/lib/vendor/thor/README.md +35 -0
- data/lib/vendor/thor/lib/thor.rb +474 -0
- data/lib/vendor/thor/lib/thor/actions.rb +318 -0
- data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
- data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
- data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/vendor/thor/lib/thor/base.rb +654 -0
- data/lib/vendor/thor/lib/thor/command.rb +136 -0
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/vendor/thor/lib/thor/error.rb +32 -0
- data/lib/vendor/thor/lib/thor/group.rb +282 -0
- data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
- data/lib/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
- data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
- data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
- data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
- data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
- data/lib/vendor/thor/lib/thor/runner.rb +322 -0
- data/lib/vendor/thor/lib/thor/shell.rb +88 -0
- data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
- data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
- data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
- data/lib/vendor/thor/lib/thor/util.rb +270 -0
- data/lib/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
- data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
- data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
- data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
- data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
- data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
- data/lib/vendor/thor/spec/actions_spec.rb +331 -0
- data/lib/vendor/thor/spec/base_spec.rb +291 -0
- data/lib/vendor/thor/spec/command_spec.rb +80 -0
- data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
- data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
- data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
- data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
- data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
- data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
- data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
- data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
- data/lib/vendor/thor/spec/fixtures/path with spaces b/data/lib/vendor/thor/spec/fixtures/path with → spaces +0 -0
- data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
- data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
- data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
- data/lib/vendor/thor/spec/group_spec.rb +222 -0
- data/lib/vendor/thor/spec/helper.rb +67 -0
- data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
- data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
- data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
- data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
- data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
- data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
- data/lib/vendor/thor/spec/register_spec.rb +197 -0
- data/lib/vendor/thor/spec/runner_spec.rb +241 -0
- data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
- data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
- data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
- data/lib/vendor/thor/spec/shell_spec.rb +47 -0
- data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
- data/lib/vendor/thor/spec/thor_spec.rb +499 -0
- data/lib/vendor/thor/spec/util_spec.rb +196 -0
- data/lib/vendor/thor/thor.gemspec +24 -0
- data/spec/auth_spec.rb +8 -0
- data/spec_helper.rb +6 -0
- metadata +135 -4
- data/tests/example_test.rb +0 -5
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
describe Thor::Actions::CreateFile do
|
5
|
+
before do
|
6
|
+
::FileUtils.rm_rf(destination_root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_file(destination=nil, config={}, options={})
|
10
|
+
@base = MyCounter.new([1, 2], options, { :destination_root => destination_root })
|
11
|
+
allow(@base).to receive(:file_name).and_return('rdoc')
|
12
|
+
|
13
|
+
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION",
|
14
|
+
{ :verbose => !@silence }.merge(config))
|
15
|
+
end
|
16
|
+
|
17
|
+
def invoke!
|
18
|
+
capture(:stdout) { @action.invoke! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoke!
|
22
|
+
capture(:stdout) { @action.revoke! }
|
23
|
+
end
|
24
|
+
|
25
|
+
def silence!
|
26
|
+
@silence = true
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#invoke!" do
|
30
|
+
it "creates a file" do
|
31
|
+
create_file("doc/config.rb")
|
32
|
+
invoke!
|
33
|
+
expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not create a file if pretending" do
|
37
|
+
create_file("doc/config.rb", {}, :pretend => true)
|
38
|
+
invoke!
|
39
|
+
expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "shows created status to the user" do
|
43
|
+
create_file("doc/config.rb")
|
44
|
+
expect(invoke!).to eq(" create doc/config.rb\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not show any information if log status is false" do
|
48
|
+
silence!
|
49
|
+
create_file("doc/config.rb")
|
50
|
+
expect(invoke!).to be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns the given destination" do
|
54
|
+
capture(:stdout) do
|
55
|
+
expect(create_file("doc/config.rb").invoke!).to eq("doc/config.rb")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "converts encoded instructions" do
|
60
|
+
create_file("doc/%file_name%.rb.tt")
|
61
|
+
invoke!
|
62
|
+
expect(File.exists?(File.join(destination_root, "doc/rdoc.rb.tt"))).to be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when file exists" do
|
66
|
+
before do
|
67
|
+
create_file("doc/config.rb")
|
68
|
+
invoke!
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "and is identical" do
|
72
|
+
it "shows identical status" do
|
73
|
+
create_file("doc/config.rb")
|
74
|
+
invoke!
|
75
|
+
expect(invoke!).to eq(" identical doc/config.rb\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "and is not identical" do
|
80
|
+
before do
|
81
|
+
File.open(File.join(destination_root, 'doc/config.rb'), 'w'){ |f| f.write("FOO = 3") }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "shows forced status to the user if force is given" do
|
85
|
+
expect(create_file("doc/config.rb", {}, :force => true)).not_to be_identical
|
86
|
+
expect(invoke!).to eq(" force doc/config.rb\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "shows skipped status to the user if skip is given" do
|
90
|
+
expect(create_file("doc/config.rb", {}, :skip => true)).not_to be_identical
|
91
|
+
expect(invoke!).to eq(" skip doc/config.rb\n")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "shows forced status to the user if force is configured" do
|
95
|
+
expect(create_file("doc/config.rb", :force => true)).not_to be_identical
|
96
|
+
expect(invoke!).to eq(" force doc/config.rb\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "shows skipped status to the user if skip is configured" do
|
100
|
+
expect(create_file("doc/config.rb", :skip => true)).not_to be_identical
|
101
|
+
expect(invoke!).to eq(" skip doc/config.rb\n")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "shows conflict status to the user" do
|
105
|
+
expect(create_file("doc/config.rb")).not_to be_identical
|
106
|
+
expect($stdin).to receive(:gets).and_return('s')
|
107
|
+
file = File.join(destination_root, 'doc/config.rb')
|
108
|
+
|
109
|
+
content = invoke!
|
110
|
+
expect(content).to match(/conflict doc\/config\.rb/)
|
111
|
+
expect(content).to match(/Overwrite #{file}\? \(enter "h" for help\) \[Ynaqdh\]/)
|
112
|
+
expect(content).to match(/skip doc\/config\.rb/)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "creates the file if the file collision menu returns true" do
|
116
|
+
create_file("doc/config.rb")
|
117
|
+
expect($stdin).to receive(:gets).and_return('y')
|
118
|
+
expect(invoke!).to match(/force doc\/config\.rb/)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "skips the file if the file collision menu returns false" do
|
122
|
+
create_file("doc/config.rb")
|
123
|
+
expect($stdin).to receive(:gets).and_return('n')
|
124
|
+
expect(invoke!).to match(/skip doc\/config\.rb/)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "executes the block given to show file content" do
|
128
|
+
create_file("doc/config.rb")
|
129
|
+
expect($stdin).to receive(:gets).and_return('d')
|
130
|
+
expect($stdin).to receive(:gets).and_return('n')
|
131
|
+
expect(@base.shell).to receive(:system).with(/diff -u/)
|
132
|
+
invoke!
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#revoke!" do
|
139
|
+
it "removes the destination file" do
|
140
|
+
create_file("doc/config.rb")
|
141
|
+
invoke!
|
142
|
+
revoke!
|
143
|
+
expect(File.exists?(@action.destination)).to be_false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "does not raise an error if the file does not exist" do
|
147
|
+
create_file("doc/config.rb")
|
148
|
+
revoke!
|
149
|
+
expect(File.exists?(@action.destination)).to be_false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#exists?" do
|
154
|
+
it "returns true if the destination file exists" do
|
155
|
+
create_file("doc/config.rb")
|
156
|
+
expect(@action.exists?).to be_false
|
157
|
+
invoke!
|
158
|
+
expect(@action.exists?).to be_true
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "#identical?" do
|
163
|
+
it "returns true if the destination file exists and is identical" do
|
164
|
+
create_file("doc/config.rb")
|
165
|
+
expect(@action.identical?).to be_false
|
166
|
+
invoke!
|
167
|
+
expect(@action.identical?).to be_true
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'thor/actions'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe Thor::Actions::CreateLink do
|
6
|
+
before do
|
7
|
+
@hardlink_to = File.join(Dir.tmpdir, 'linkdest.rb')
|
8
|
+
::FileUtils.rm_rf(destination_root)
|
9
|
+
::FileUtils.rm_rf(@hardlink_to)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_link(destination=nil, config={}, options={})
|
13
|
+
@base = MyCounter.new([1,2], options, { :destination_root => destination_root })
|
14
|
+
allow(@base).to receive(:file_name).and_return('rdoc')
|
15
|
+
|
16
|
+
@tempfile = Tempfile.new("config.rb")
|
17
|
+
|
18
|
+
@action = Thor::Actions::CreateLink.new(@base, destination, @tempfile.path,
|
19
|
+
{ :verbose => !@silence }.merge(config))
|
20
|
+
end
|
21
|
+
|
22
|
+
def invoke!
|
23
|
+
capture(:stdout) { @action.invoke! }
|
24
|
+
end
|
25
|
+
|
26
|
+
def revoke!
|
27
|
+
capture(:stdout) { @action.revoke! }
|
28
|
+
end
|
29
|
+
|
30
|
+
def silence!
|
31
|
+
@silence = true
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#invoke!" do
|
35
|
+
it "creates a symbolic link for :symbolic => true" do
|
36
|
+
create_link("doc/config.rb", :symbolic => true)
|
37
|
+
invoke!
|
38
|
+
destination_path = File.join(destination_root, "doc/config.rb")
|
39
|
+
expect(File.exists?(destination_path)).to be_true
|
40
|
+
expect(File.symlink?(destination_path)).to be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a hard link for :symbolic => false" do
|
44
|
+
create_link(@hardlink_to, :symbolic => false)
|
45
|
+
invoke!
|
46
|
+
destination_path = @hardlink_to
|
47
|
+
expect(File.exists?(destination_path)).to be_true
|
48
|
+
expect(File.symlink?(destination_path)).to be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
it "creates a symbolic link by default" do
|
52
|
+
create_link("doc/config.rb")
|
53
|
+
invoke!
|
54
|
+
destination_path = File.join(destination_root, "doc/config.rb")
|
55
|
+
expect(File.exists?(destination_path)).to be_true
|
56
|
+
expect(File.symlink?(destination_path)).to be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "does not create a link if pretending" do
|
60
|
+
create_link("doc/config.rb", {}, :pretend => true)
|
61
|
+
invoke!
|
62
|
+
expect(File.exists?(File.join(destination_root, "doc/config.rb"))).to be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "shows created status to the user" do
|
66
|
+
create_link("doc/config.rb")
|
67
|
+
expect(invoke!).to eq(" create doc/config.rb\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not show any information if log status is false" do
|
71
|
+
silence!
|
72
|
+
create_link("doc/config.rb")
|
73
|
+
expect(invoke!).to be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#identical?" do
|
78
|
+
it "returns true if the destination link exists and is identical" do
|
79
|
+
create_link("doc/config.rb")
|
80
|
+
expect(@action.identical?).to be_false
|
81
|
+
invoke!
|
82
|
+
expect(@action.identical?).to be_true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#revoke!" do
|
87
|
+
it "removes the symbolic link of non-existent destination" do
|
88
|
+
create_link("doc/config.rb")
|
89
|
+
invoke!
|
90
|
+
File.delete(@tempfile.path)
|
91
|
+
revoke!
|
92
|
+
expect(File.symlink?(@action.destination)).to be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
describe Thor::Actions::Directory do
|
5
|
+
before do
|
6
|
+
::FileUtils.rm_rf(destination_root)
|
7
|
+
allow(invoker).to receive(:file_name).and_return("rdoc")
|
8
|
+
end
|
9
|
+
|
10
|
+
def invoker
|
11
|
+
@invoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root })
|
12
|
+
end
|
13
|
+
|
14
|
+
def revoker
|
15
|
+
@revoker ||= WhinyGenerator.new([1,2], {}, { :destination_root => destination_root, :behavior => :revoke })
|
16
|
+
end
|
17
|
+
|
18
|
+
def invoke!(*args, &block)
|
19
|
+
capture(:stdout){ invoker.directory(*args, &block) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def revoke!(*args, &block)
|
23
|
+
capture(:stdout){ revoker.directory(*args, &block) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def exists_and_identical?(source_path, destination_path)
|
27
|
+
%w(config.rb README).each do |file|
|
28
|
+
source = File.join(source_root, source_path, file)
|
29
|
+
destination = File.join(destination_root, destination_path, file)
|
30
|
+
|
31
|
+
expect(File.exists?(destination)).to be_true
|
32
|
+
expect(FileUtils.identical?(source, destination)).to be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#invoke!" do
|
37
|
+
it "raises an error if the source does not exist" do
|
38
|
+
expect {
|
39
|
+
invoke! "unknown"
|
40
|
+
}.to raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does not create a directory in pretend mode" do
|
44
|
+
invoke! "doc", "ghost", :pretend => true
|
45
|
+
expect(File.exists?("ghost")).to be_false
|
46
|
+
end
|
47
|
+
|
48
|
+
it "copies the whole directory recursively to the default destination" do
|
49
|
+
invoke! "doc"
|
50
|
+
exists_and_identical?("doc", "doc")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "copies the whole directory recursively to the specified destination" do
|
54
|
+
invoke! "doc", "docs"
|
55
|
+
exists_and_identical?("doc", "docs")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "copies only the first level files if recursive" do
|
59
|
+
invoke! ".", "commands", :recursive => false
|
60
|
+
|
61
|
+
file = File.join(destination_root, "commands", "group.thor")
|
62
|
+
expect(File.exists?(file)).to be_true
|
63
|
+
|
64
|
+
file = File.join(destination_root, "commands", "doc")
|
65
|
+
expect(File.exists?(file)).to be_false
|
66
|
+
|
67
|
+
file = File.join(destination_root, "commands", "doc", "README")
|
68
|
+
expect(File.exists?(file)).to be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "ignores files within excluding/ directories when exclude_pattern is provided" do
|
72
|
+
invoke! "doc", "docs", :exclude_pattern => /excluding\//
|
73
|
+
file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
|
74
|
+
expect(File.exists?(file)).to be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "copies and evaluates files within excluding/ directory when no exclude_pattern is present" do
|
78
|
+
invoke! "doc", "docs"
|
79
|
+
file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
|
80
|
+
expect(File.exists?(file)).to be_true
|
81
|
+
expect(File.read(file)).to eq("BAR = BAR\n")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "copies files from the source relative to the current path" do
|
85
|
+
invoker.inside "doc" do
|
86
|
+
invoke! "."
|
87
|
+
end
|
88
|
+
exists_and_identical?("doc", "doc")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "copies and evaluates templates" do
|
92
|
+
invoke! "doc", "docs"
|
93
|
+
file = File.join(destination_root, "docs", "rdoc.rb")
|
94
|
+
expect(File.exists?(file)).to be_true
|
95
|
+
expect(File.read(file)).to eq("FOO = FOO\n")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "copies directories and preserves file mode" do
|
99
|
+
invoke! "preserve", "preserved", :mode => :preserve
|
100
|
+
original = File.join(source_root, "preserve", "script.sh")
|
101
|
+
copy = File.join(destination_root, "preserved", "script.sh")
|
102
|
+
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "copies directories" do
|
106
|
+
invoke! "doc", "docs"
|
107
|
+
file = File.join(destination_root, "docs", "components")
|
108
|
+
expect(File.exists?(file)).to be_true
|
109
|
+
expect(File.directory?(file)).to be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it "does not copy .empty_directory files" do
|
113
|
+
invoke! "doc", "docs"
|
114
|
+
file = File.join(destination_root, "docs", "components", ".empty_directory")
|
115
|
+
expect(File.exists?(file)).to be_false
|
116
|
+
end
|
117
|
+
|
118
|
+
it "copies directories even if they are empty" do
|
119
|
+
invoke! "doc/components", "docs/components"
|
120
|
+
file = File.join(destination_root, "docs", "components")
|
121
|
+
expect(File.exists?(file)).to be_true
|
122
|
+
end
|
123
|
+
|
124
|
+
it "does not copy empty directories twice" do
|
125
|
+
content = invoke!("doc/components", "docs/components")
|
126
|
+
expect(content).not_to match(/exist/)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "logs status" do
|
130
|
+
content = invoke!("doc")
|
131
|
+
expect(content).to match(/create doc\/README/)
|
132
|
+
expect(content).to match(/create doc\/config\.rb/)
|
133
|
+
expect(content).to match(/create doc\/rdoc\.rb/)
|
134
|
+
expect(content).to match(/create doc\/components/)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "yields a block" do
|
138
|
+
checked = false
|
139
|
+
invoke!("doc") do |content|
|
140
|
+
checked ||= !!(content =~ /FOO/)
|
141
|
+
end
|
142
|
+
expect(checked).to be_true
|
143
|
+
end
|
144
|
+
|
145
|
+
it "works with glob characters in the path" do
|
146
|
+
content = invoke!("app{1}")
|
147
|
+
expect(content).to match(/create app\{1\}\/README/)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#revoke!" do
|
152
|
+
it "removes the destination file" do
|
153
|
+
invoke! "doc"
|
154
|
+
revoke! "doc"
|
155
|
+
|
156
|
+
expect(File.exists?(File.join(destination_root, "doc", "README"))).to be_false
|
157
|
+
expect(File.exists?(File.join(destination_root, "doc", "config.rb"))).to be_false
|
158
|
+
expect(File.exists?(File.join(destination_root, "doc", "components"))).to be_false
|
159
|
+
end
|
160
|
+
|
161
|
+
it "works with glob characters in the path" do
|
162
|
+
invoke! "app{1}"
|
163
|
+
expect(File.exists?(File.join(destination_root, "app{1}", "README"))).to be_true
|
164
|
+
|
165
|
+
revoke! "app{1}"
|
166
|
+
expect(File.exists?(File.join(destination_root, "app{1}", "README"))).to be_false
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
describe Thor::Actions::EmptyDirectory do
|
5
|
+
before do
|
6
|
+
::FileUtils.rm_rf(destination_root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def empty_directory(destination, options={})
|
10
|
+
@action = Thor::Actions::EmptyDirectory.new(base, destination)
|
11
|
+
end
|
12
|
+
|
13
|
+
def invoke!
|
14
|
+
capture(:stdout) { @action.invoke! }
|
15
|
+
end
|
16
|
+
|
17
|
+
def revoke!
|
18
|
+
capture(:stdout) { @action.revoke! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def base
|
22
|
+
@base ||= MyCounter.new([1,2], {}, { :destination_root => destination_root })
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#destination" do
|
26
|
+
it "returns the full destination with the destination_root" do
|
27
|
+
expect(empty_directory('doc').destination).to eq(File.join(destination_root, 'doc'))
|
28
|
+
end
|
29
|
+
|
30
|
+
it "takes relative root into account" do
|
31
|
+
base.inside('doc') do
|
32
|
+
expect(empty_directory('contents').destination).to eq(File.join(destination_root, 'doc', 'contents'))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#relative_destination" do
|
38
|
+
it "returns the relative destination to the original destination root" do
|
39
|
+
base.inside('doc') do
|
40
|
+
expect(empty_directory('contents').relative_destination).to eq('doc/contents')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#given_destination" do
|
46
|
+
it "returns the destination supplied by the user" do
|
47
|
+
base.inside('doc') do
|
48
|
+
expect(empty_directory('contents').given_destination).to eq('contents')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#invoke!" do
|
54
|
+
it "copies the file to the specified destination" do
|
55
|
+
empty_directory("doc")
|
56
|
+
invoke!
|
57
|
+
expect(File.exists?(File.join(destination_root, "doc"))).to be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "shows created status to the user" do
|
61
|
+
empty_directory("doc")
|
62
|
+
expect(invoke!).to eq(" create doc\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "does not create a directory if pretending" do
|
66
|
+
base.inside("foo", :pretend => true) do
|
67
|
+
empty_directory("ghost")
|
68
|
+
end
|
69
|
+
expect(File.exists?(File.join(base.destination_root, "ghost"))).to be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "when directory exists" do
|
73
|
+
it "shows exist status" do
|
74
|
+
empty_directory("doc")
|
75
|
+
invoke!
|
76
|
+
expect(invoke!).to eq(" exist doc\n")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#revoke!" do
|
82
|
+
it "removes the destination file" do
|
83
|
+
empty_directory("doc")
|
84
|
+
invoke!
|
85
|
+
revoke!
|
86
|
+
expect(File.exists?(@action.destination)).to be_false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#exists?" do
|
91
|
+
it "returns true if the destination file exists" do
|
92
|
+
empty_directory("doc")
|
93
|
+
expect(@action.exists?).to be_false
|
94
|
+
invoke!
|
95
|
+
expect(@action.exists?).to be_true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "protected methods" do
|
100
|
+
describe "#convert_encoded_instructions" do
|
101
|
+
before do
|
102
|
+
empty_directory("test_dir")
|
103
|
+
allow(@action.base).to receive(:file_name).and_return("expected")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "accepts and executes a 'legal' %\w+% encoded instruction" do
|
107
|
+
expect(@action.send(:convert_encoded_instructions, "%file_name%.txt")).to eq("expected.txt")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "accepts and executes a private %\w+% encoded instruction" do
|
111
|
+
@action.base.extend Module.new {
|
112
|
+
private
|
113
|
+
def private_file_name
|
114
|
+
"expected"
|
115
|
+
end
|
116
|
+
}
|
117
|
+
expect(@action.send(:convert_encoded_instructions, "%private_file_name%.txt")).to eq("expected.txt")
|
118
|
+
end
|
119
|
+
|
120
|
+
it "ignores an 'illegal' %\w+% encoded instruction" do
|
121
|
+
expect(@action.send(:convert_encoded_instructions, "%some_name%.txt")).to eq("%some_name%.txt")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "ignores incorrectly encoded instruction" do
|
125
|
+
expect(@action.send(:convert_encoded_instructions, "%some.name%.txt")).to eq("%some.name%.txt")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|