thor 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +13 -7
- data/Thorfile +4 -5
- data/bin/thor +1 -1
- data/lib/thor.rb +78 -67
- data/lib/thor/actions.rb +57 -56
- data/lib/thor/actions/create_file.rb +33 -35
- data/lib/thor/actions/create_link.rb +2 -3
- data/lib/thor/actions/directory.rb +37 -38
- data/lib/thor/actions/empty_directory.rb +67 -69
- data/lib/thor/actions/file_manipulation.rb +17 -15
- data/lib/thor/actions/inject_into_file.rb +27 -29
- data/lib/thor/base.rb +193 -189
- data/lib/thor/command.rb +20 -23
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +21 -24
- data/lib/thor/core_ext/io_binary_read.rb +2 -4
- data/lib/thor/core_ext/ordered_hash.rb +9 -11
- data/lib/thor/error.rb +5 -1
- data/lib/thor/group.rb +53 -54
- data/lib/thor/invocation.rb +44 -38
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/line_editor/basic.rb +35 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/parser/argument.rb +28 -29
- data/lib/thor/parser/arguments.rb +102 -98
- data/lib/thor/parser/option.rb +26 -22
- data/lib/thor/parser/options.rb +86 -86
- data/lib/thor/rake_compat.rb +9 -10
- data/lib/thor/runner.rb +141 -141
- data/lib/thor/shell.rb +27 -34
- data/lib/thor/shell/basic.rb +91 -63
- data/lib/thor/shell/color.rb +44 -43
- data/lib/thor/shell/html.rb +59 -60
- data/lib/thor/util.rb +24 -27
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +25 -27
- data/spec/actions/create_link_spec.rb +19 -18
- data/spec/actions/directory_spec.rb +31 -31
- data/spec/actions/empty_directory_spec.rb +18 -18
- data/spec/actions/file_manipulation_spec.rb +38 -28
- data/spec/actions/inject_into_file_spec.rb +13 -13
- data/spec/actions_spec.rb +43 -43
- data/spec/base_spec.rb +45 -38
- data/spec/command_spec.rb +13 -14
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -19
- data/spec/core_ext/ordered_hash_spec.rb +6 -6
- data/spec/exit_condition_spec.rb +4 -4
- data/spec/fixtures/invoke.thor +19 -0
- data/spec/fixtures/script.thor +1 -1
- data/spec/group_spec.rb +30 -24
- data/spec/helper.rb +28 -15
- data/spec/invocation_spec.rb +39 -19
- data/spec/line_editor/basic_spec.rb +28 -0
- data/spec/line_editor/readline_spec.rb +69 -0
- data/spec/line_editor_spec.rb +43 -0
- data/spec/parser/argument_spec.rb +12 -12
- data/spec/parser/arguments_spec.rb +11 -11
- data/spec/parser/option_spec.rb +33 -25
- data/spec/parser/options_spec.rb +66 -52
- data/spec/quality_spec.rb +75 -0
- data/spec/rake_compat_spec.rb +10 -10
- data/spec/register_spec.rb +60 -30
- data/spec/runner_spec.rb +67 -62
- data/spec/sandbox/application.rb +2 -0
- data/spec/sandbox/app{1}/README +3 -0
- data/spec/sandbox/bundle/execute.rb +6 -0
- data/spec/sandbox/bundle/main.thor +1 -0
- data/spec/sandbox/command.thor +10 -0
- data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
- data/spec/sandbox/doc/COMMENTER +11 -0
- data/spec/sandbox/doc/README +3 -0
- data/spec/sandbox/doc/block_helper.rb +3 -0
- data/spec/sandbox/doc/config.rb +1 -0
- data/spec/sandbox/doc/config.yaml.tt +1 -0
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/sandbox/enum.thor +10 -0
- data/spec/sandbox/group.thor +128 -0
- data/spec/sandbox/invoke.thor +131 -0
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +3 -0
- data/spec/sandbox/script.thor +220 -0
- data/spec/sandbox/subcommand.thor +17 -0
- data/spec/shell/basic_spec.rb +107 -86
- data/spec/shell/color_spec.rb +32 -8
- data/spec/shell/html_spec.rb +3 -4
- data/spec/shell_spec.rb +7 -7
- data/spec/subcommand_spec.rb +20 -2
- data/spec/thor_spec.rb +111 -97
- data/spec/util_spec.rb +30 -30
- data/thor.gemspec +14 -14
- metadata +69 -25
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "helper"
|
2
|
+
require "thor/actions"
|
3
|
+
require "tempfile"
|
4
4
|
|
5
5
|
describe Thor::Actions::CreateLink do
|
6
6
|
before do
|
7
|
-
@
|
7
|
+
@silence = false
|
8
|
+
@hardlink_to = File.join(Dir.tmpdir, "linkdest.rb")
|
8
9
|
::FileUtils.rm_rf(destination_root)
|
9
10
|
::FileUtils.rm_rf(@hardlink_to)
|
10
11
|
end
|
11
12
|
|
12
|
-
def create_link(destination=nil, config={}, options={})
|
13
|
-
@base = MyCounter.new([1,2], options,
|
14
|
-
@base.
|
13
|
+
def create_link(destination = nil, config = {}, options = {})
|
14
|
+
@base = MyCounter.new([1, 2], options, :destination_root => destination_root)
|
15
|
+
allow(@base).to receive(:file_name).and_return("rdoc")
|
15
16
|
|
16
17
|
@tempfile = Tempfile.new("config.rb")
|
17
18
|
|
18
19
|
@action = Thor::Actions::CreateLink.new(@base, destination, @tempfile.path,
|
19
|
-
{
|
20
|
+
{:verbose => !@silence}.merge(config))
|
20
21
|
end
|
21
22
|
|
22
23
|
def invoke!
|
@@ -36,30 +37,30 @@ describe Thor::Actions::CreateLink do
|
|
36
37
|
create_link("doc/config.rb", :symbolic => true)
|
37
38
|
invoke!
|
38
39
|
destination_path = File.join(destination_root, "doc/config.rb")
|
39
|
-
expect(File.
|
40
|
-
expect(File.symlink?(destination_path)).to
|
40
|
+
expect(File.exist?(destination_path)).to be true
|
41
|
+
expect(File.symlink?(destination_path)).to be true
|
41
42
|
end
|
42
43
|
|
43
44
|
it "creates a hard link for :symbolic => false" do
|
44
45
|
create_link(@hardlink_to, :symbolic => false)
|
45
46
|
invoke!
|
46
47
|
destination_path = @hardlink_to
|
47
|
-
expect(File.
|
48
|
-
expect(File.symlink?(destination_path)).to
|
48
|
+
expect(File.exist?(destination_path)).to be true
|
49
|
+
expect(File.symlink?(destination_path)).to be false
|
49
50
|
end
|
50
51
|
|
51
52
|
it "creates a symbolic link by default" do
|
52
53
|
create_link("doc/config.rb")
|
53
54
|
invoke!
|
54
55
|
destination_path = File.join(destination_root, "doc/config.rb")
|
55
|
-
expect(File.
|
56
|
-
expect(File.symlink?(destination_path)).to
|
56
|
+
expect(File.exist?(destination_path)).to be true
|
57
|
+
expect(File.symlink?(destination_path)).to be true
|
57
58
|
end
|
58
59
|
|
59
60
|
it "does not create a link if pretending" do
|
60
61
|
create_link("doc/config.rb", {}, :pretend => true)
|
61
62
|
invoke!
|
62
|
-
expect(File.
|
63
|
+
expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be false
|
63
64
|
end
|
64
65
|
|
65
66
|
it "shows created status to the user" do
|
@@ -77,9 +78,9 @@ describe Thor::Actions::CreateLink do
|
|
77
78
|
describe "#identical?" do
|
78
79
|
it "returns true if the destination link exists and is identical" do
|
79
80
|
create_link("doc/config.rb")
|
80
|
-
expect(@action.identical?).to
|
81
|
+
expect(@action.identical?).to be false
|
81
82
|
invoke!
|
82
|
-
expect(@action.identical?).to
|
83
|
+
expect(@action.identical?).to be true
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
@@ -89,7 +90,7 @@ describe Thor::Actions::CreateLink do
|
|
89
90
|
invoke!
|
90
91
|
File.delete(@tempfile.path)
|
91
92
|
revoke!
|
92
|
-
expect(File.symlink?(@action.destination)).to
|
93
|
+
expect(File.symlink?(@action.destination)).to be false
|
93
94
|
end
|
94
95
|
end
|
95
96
|
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "helper"
|
2
|
+
require "thor/actions"
|
3
3
|
|
4
4
|
describe Thor::Actions::Directory do
|
5
5
|
before do
|
6
6
|
::FileUtils.rm_rf(destination_root)
|
7
|
-
invoker.
|
7
|
+
allow(invoker).to receive(:file_name).and_return("rdoc")
|
8
8
|
end
|
9
9
|
|
10
10
|
def invoker
|
11
|
-
@invoker ||= WhinyGenerator.new([1,2], {},
|
11
|
+
@invoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root)
|
12
12
|
end
|
13
13
|
|
14
14
|
def revoker
|
15
|
-
@revoker ||= WhinyGenerator.new([1,2], {},
|
15
|
+
@revoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke)
|
16
16
|
end
|
17
17
|
|
18
18
|
def invoke!(*args, &block)
|
19
|
-
capture(:stdout){ invoker.directory(*args, &block) }
|
19
|
+
capture(:stdout) { invoker.directory(*args, &block) }
|
20
20
|
end
|
21
21
|
|
22
22
|
def revoke!(*args, &block)
|
23
|
-
capture(:stdout){ revoker.directory(*args, &block) }
|
23
|
+
capture(:stdout) { revoker.directory(*args, &block) }
|
24
24
|
end
|
25
25
|
|
26
26
|
def exists_and_identical?(source_path, destination_path)
|
27
|
-
%w
|
27
|
+
%w[config.rb README].each do |file|
|
28
28
|
source = File.join(source_root, source_path, file)
|
29
29
|
destination = File.join(destination_root, destination_path, file)
|
30
30
|
|
31
|
-
expect(File.
|
32
|
-
expect(FileUtils.identical?(source, destination)).to
|
31
|
+
expect(File.exist?(destination)).to be true
|
32
|
+
expect(FileUtils.identical?(source, destination)).to be true
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "#invoke!" do
|
37
37
|
it "raises an error if the source does not exist" do
|
38
|
-
expect
|
38
|
+
expect do
|
39
39
|
invoke! "unknown"
|
40
|
-
|
40
|
+
end.to raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "does not create a directory in pretend mode" do
|
44
44
|
invoke! "doc", "ghost", :pretend => true
|
45
|
-
expect(File.
|
45
|
+
expect(File.exist?("ghost")).to be false
|
46
46
|
end
|
47
47
|
|
48
48
|
it "copies the whole directory recursively to the default destination" do
|
@@ -59,25 +59,25 @@ describe Thor::Actions::Directory do
|
|
59
59
|
invoke! ".", "commands", :recursive => false
|
60
60
|
|
61
61
|
file = File.join(destination_root, "commands", "group.thor")
|
62
|
-
expect(File.
|
62
|
+
expect(File.exist?(file)).to be true
|
63
63
|
|
64
64
|
file = File.join(destination_root, "commands", "doc")
|
65
|
-
expect(File.
|
65
|
+
expect(File.exist?(file)).to be false
|
66
66
|
|
67
67
|
file = File.join(destination_root, "commands", "doc", "README")
|
68
|
-
expect(File.
|
68
|
+
expect(File.exist?(file)).to be false
|
69
69
|
end
|
70
70
|
|
71
71
|
it "ignores files within excluding/ directories when exclude_pattern is provided" do
|
72
72
|
invoke! "doc", "docs", :exclude_pattern => /excluding\//
|
73
73
|
file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
|
74
|
-
expect(File.
|
74
|
+
expect(File.exist?(file)).to be false
|
75
75
|
end
|
76
76
|
|
77
|
-
it "copies and
|
77
|
+
it "copies and evaluates files within excluding/ directory when no exclude_pattern is present" do
|
78
78
|
invoke! "doc", "docs"
|
79
79
|
file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
|
80
|
-
expect(File.
|
80
|
+
expect(File.exist?(file)).to be true
|
81
81
|
expect(File.read(file)).to eq("BAR = BAR\n")
|
82
82
|
end
|
83
83
|
|
@@ -91,11 +91,11 @@ describe Thor::Actions::Directory do
|
|
91
91
|
it "copies and evaluates templates" do
|
92
92
|
invoke! "doc", "docs"
|
93
93
|
file = File.join(destination_root, "docs", "rdoc.rb")
|
94
|
-
expect(File.
|
94
|
+
expect(File.exist?(file)).to be true
|
95
95
|
expect(File.read(file)).to eq("FOO = FOO\n")
|
96
96
|
end
|
97
97
|
|
98
|
-
it "copies directories and
|
98
|
+
it "copies directories and preserves file mode" do
|
99
99
|
invoke! "preserve", "preserved", :mode => :preserve
|
100
100
|
original = File.join(source_root, "preserve", "script.sh")
|
101
101
|
copy = File.join(destination_root, "preserved", "script.sh")
|
@@ -105,20 +105,20 @@ describe Thor::Actions::Directory do
|
|
105
105
|
it "copies directories" do
|
106
106
|
invoke! "doc", "docs"
|
107
107
|
file = File.join(destination_root, "docs", "components")
|
108
|
-
expect(File.
|
109
|
-
expect(File.directory?(file)).to
|
108
|
+
expect(File.exist?(file)).to be true
|
109
|
+
expect(File.directory?(file)).to be true
|
110
110
|
end
|
111
111
|
|
112
112
|
it "does not copy .empty_directory files" do
|
113
113
|
invoke! "doc", "docs"
|
114
114
|
file = File.join(destination_root, "docs", "components", ".empty_directory")
|
115
|
-
expect(File.
|
115
|
+
expect(File.exist?(file)).to be false
|
116
116
|
end
|
117
117
|
|
118
118
|
it "copies directories even if they are empty" do
|
119
119
|
invoke! "doc/components", "docs/components"
|
120
120
|
file = File.join(destination_root, "docs", "components")
|
121
|
-
expect(File.
|
121
|
+
expect(File.exist?(file)).to be true
|
122
122
|
end
|
123
123
|
|
124
124
|
it "does not copy empty directories twice" do
|
@@ -139,7 +139,7 @@ describe Thor::Actions::Directory do
|
|
139
139
|
invoke!("doc") do |content|
|
140
140
|
checked ||= !!(content =~ /FOO/)
|
141
141
|
end
|
142
|
-
expect(checked).to
|
142
|
+
expect(checked).to be true
|
143
143
|
end
|
144
144
|
|
145
145
|
it "works with glob characters in the path" do
|
@@ -153,17 +153,17 @@ describe Thor::Actions::Directory do
|
|
153
153
|
invoke! "doc"
|
154
154
|
revoke! "doc"
|
155
155
|
|
156
|
-
expect(File.
|
157
|
-
expect(File.
|
158
|
-
expect(File.
|
156
|
+
expect(File.exist?(File.join(destination_root, "doc", "README"))).to be false
|
157
|
+
expect(File.exist?(File.join(destination_root, "doc", "config.rb"))).to be false
|
158
|
+
expect(File.exist?(File.join(destination_root, "doc", "components"))).to be false
|
159
159
|
end
|
160
160
|
|
161
161
|
it "works with glob characters in the path" do
|
162
162
|
invoke! "app{1}"
|
163
|
-
expect(File.
|
163
|
+
expect(File.exist?(File.join(destination_root, "app{1}", "README"))).to be true
|
164
164
|
|
165
165
|
revoke! "app{1}"
|
166
|
-
expect(File.
|
166
|
+
expect(File.exist?(File.join(destination_root, "app{1}", "README"))).to be false
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "helper"
|
2
|
+
require "thor/actions"
|
3
3
|
|
4
4
|
describe Thor::Actions::EmptyDirectory do
|
5
5
|
before do
|
6
6
|
::FileUtils.rm_rf(destination_root)
|
7
7
|
end
|
8
8
|
|
9
|
-
def empty_directory(destination, options={})
|
9
|
+
def empty_directory(destination, options = {})
|
10
10
|
@action = Thor::Actions::EmptyDirectory.new(base, destination)
|
11
11
|
end
|
12
12
|
|
@@ -19,33 +19,33 @@ describe Thor::Actions::EmptyDirectory do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def base
|
22
|
-
@base ||= MyCounter.new([1,2], {},
|
22
|
+
@base ||= MyCounter.new([1, 2], {}, :destination_root => destination_root)
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#destination" do
|
26
26
|
it "returns the full destination with the destination_root" do
|
27
|
-
expect(empty_directory(
|
27
|
+
expect(empty_directory("doc").destination).to eq(File.join(destination_root, "doc"))
|
28
28
|
end
|
29
29
|
|
30
30
|
it "takes relative root into account" do
|
31
|
-
base.inside(
|
32
|
-
expect(empty_directory(
|
31
|
+
base.inside("doc") do
|
32
|
+
expect(empty_directory("contents").destination).to eq(File.join(destination_root, "doc", "contents"))
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "#relative_destination" do
|
38
38
|
it "returns the relative destination to the original destination root" do
|
39
|
-
base.inside(
|
40
|
-
expect(empty_directory(
|
39
|
+
base.inside("doc") do
|
40
|
+
expect(empty_directory("contents").relative_destination).to eq("doc/contents")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#given_destination" do
|
46
46
|
it "returns the destination supplied by the user" do
|
47
|
-
base.inside(
|
48
|
-
expect(empty_directory(
|
47
|
+
base.inside("doc") do
|
48
|
+
expect(empty_directory("contents").given_destination).to eq("contents")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -54,7 +54,7 @@ describe Thor::Actions::EmptyDirectory do
|
|
54
54
|
it "copies the file to the specified destination" do
|
55
55
|
empty_directory("doc")
|
56
56
|
invoke!
|
57
|
-
expect(File.
|
57
|
+
expect(File.exist?(File.join(destination_root, "doc"))).to be true
|
58
58
|
end
|
59
59
|
|
60
60
|
it "shows created status to the user" do
|
@@ -66,7 +66,7 @@ describe Thor::Actions::EmptyDirectory do
|
|
66
66
|
base.inside("foo", :pretend => true) do
|
67
67
|
empty_directory("ghost")
|
68
68
|
end
|
69
|
-
expect(File.
|
69
|
+
expect(File.exist?(File.join(base.destination_root, "ghost"))).to be false
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "when directory exists" do
|
@@ -83,16 +83,16 @@ describe Thor::Actions::EmptyDirectory do
|
|
83
83
|
empty_directory("doc")
|
84
84
|
invoke!
|
85
85
|
revoke!
|
86
|
-
expect(File.
|
86
|
+
expect(File.exist?(@action.destination)).to be false
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "#exists?" do
|
91
91
|
it "returns true if the destination file exists" do
|
92
92
|
empty_directory("doc")
|
93
|
-
expect(@action.exists?).to
|
93
|
+
expect(@action.exists?).to be false
|
94
94
|
invoke!
|
95
|
-
expect(@action.exists?).to
|
95
|
+
expect(@action.exists?).to be true
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -100,7 +100,7 @@ describe Thor::Actions::EmptyDirectory do
|
|
100
100
|
describe "#convert_encoded_instructions" do
|
101
101
|
before do
|
102
102
|
empty_directory("test_dir")
|
103
|
-
@action.base.
|
103
|
+
allow(@action.base).to receive(:file_name).and_return("expected")
|
104
104
|
end
|
105
105
|
|
106
106
|
it "accepts and executes a 'legal' %\w+% encoded instruction" do
|
@@ -109,10 +109,10 @@ describe Thor::Actions::EmptyDirectory do
|
|
109
109
|
|
110
110
|
it "accepts and executes a private %\w+% encoded instruction" do
|
111
111
|
@action.base.extend Module.new {
|
112
|
-
private
|
113
112
|
def private_file_name
|
114
113
|
"expected"
|
115
114
|
end
|
115
|
+
private :private_file_name
|
116
116
|
}
|
117
117
|
expect(@action.send(:convert_encoded_instructions, "%private_file_name%.txt")).to eq("expected.txt")
|
118
118
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class Application; end
|
4
4
|
|
5
5
|
describe Thor::Actions do
|
6
|
-
def runner(options={})
|
7
|
-
@runner ||= MyCounter.new([1], options,
|
6
|
+
def runner(options = {})
|
7
|
+
@runner ||= MyCounter.new([1], options, :destination_root => destination_root)
|
8
8
|
end
|
9
9
|
|
10
10
|
def action(*args, &block)
|
@@ -12,11 +12,11 @@ describe Thor::Actions do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def exists_and_identical?(source, destination)
|
15
|
-
|
16
|
-
|
15
|
+
destination = File.join(destination_root, destination)
|
16
|
+
expect(File.exist?(destination)).to be true
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
source = File.join(source_root, source)
|
19
|
+
expect(FileUtils).to be_identical(source, destination)
|
20
20
|
end
|
21
21
|
|
22
22
|
def file
|
@@ -29,23 +29,23 @@ describe Thor::Actions do
|
|
29
29
|
|
30
30
|
describe "#chmod" do
|
31
31
|
it "executes the command given" do
|
32
|
-
FileUtils.
|
32
|
+
expect(FileUtils).to receive(:chmod_R).with(0755, file) # rubocop:disable SymbolName
|
33
33
|
action :chmod, "foo", 0755
|
34
34
|
end
|
35
35
|
|
36
|
-
it "does not execute the command if pretending
|
37
|
-
FileUtils.
|
36
|
+
it "does not execute the command if pretending" do
|
37
|
+
expect(FileUtils).not_to receive(:chmod_R) # rubocop:disable SymbolName
|
38
38
|
runner(:pretend => true)
|
39
39
|
action :chmod, "foo", 0755
|
40
40
|
end
|
41
41
|
|
42
42
|
it "logs status" do
|
43
|
-
FileUtils.
|
43
|
+
expect(FileUtils).to receive(:chmod_R).with(0755, file) # rubocop:disable SymbolName
|
44
44
|
expect(action(:chmod, "foo", 0755)).to eq(" chmod foo\n")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "does not log status if required" do
|
48
|
-
FileUtils.
|
48
|
+
expect(FileUtils).to receive(:chmod_R).with(0755, file) # rubocop:disable SymbolName
|
49
49
|
expect(action(:chmod, "foo", 0755, :verbose => false)).to be_empty
|
50
50
|
end
|
51
51
|
end
|
@@ -122,7 +122,7 @@ describe Thor::Actions do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it "allows the destination to be set as a block result" do
|
125
|
-
action(:get, "doc/README"){ |c| "docs/README" }
|
125
|
+
action(:get, "doc/README") { |c| "docs/README" }
|
126
126
|
exists_and_identical?("doc/README", "docs/README")
|
127
127
|
end
|
128
128
|
|
@@ -138,7 +138,7 @@ describe Thor::Actions do
|
|
138
138
|
|
139
139
|
it "accepts http remote sources" do
|
140
140
|
body = "__start__\nHTTPFILE\n__end__\n"
|
141
|
-
FakeWeb.register_uri(:get,
|
141
|
+
FakeWeb.register_uri(:get, "http://example.com/file.txt", :body => body)
|
142
142
|
action :get, "http://example.com/file.txt" do |content|
|
143
143
|
expect(content).to eq(body)
|
144
144
|
end
|
@@ -147,7 +147,7 @@ describe Thor::Actions do
|
|
147
147
|
|
148
148
|
it "accepts https remote sources" do
|
149
149
|
body = "__start__\nHTTPSFILE\n__end__\n"
|
150
|
-
FakeWeb.register_uri(:get,
|
150
|
+
FakeWeb.register_uri(:get, "https://example.com/file.txt", :body => body)
|
151
151
|
action :get, "https://example.com/file.txt" do |content|
|
152
152
|
expect(content).to eq(body)
|
153
153
|
end
|
@@ -172,23 +172,33 @@ describe Thor::Actions do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it "copies the template to the specified destination" do
|
175
|
+
runner.instance_variable_set("@klass", "Config")
|
175
176
|
action :template, "doc/config.rb", "doc/configuration.rb"
|
176
177
|
file = File.join(destination_root, "doc/configuration.rb")
|
177
|
-
expect(File.
|
178
|
+
expect(File.exist?(file)).to be true
|
178
179
|
end
|
179
180
|
|
180
|
-
it "converts
|
181
|
-
runner.
|
181
|
+
it "converts encoded instructions" do
|
182
|
+
expect(runner).to receive(:file_name).and_return("rdoc")
|
182
183
|
action :template, "doc/%file_name%.rb.tt"
|
183
184
|
file = File.join(destination_root, "doc/rdoc.rb")
|
184
|
-
expect(File.
|
185
|
+
expect(File.exist?(file)).to be true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "accepts filename without .tt for template method" do
|
189
|
+
expect(runner).to receive(:file_name).and_return("rdoc")
|
190
|
+
action :template, "doc/%file_name%.rb"
|
191
|
+
file = File.join(destination_root, "doc/rdoc.rb")
|
192
|
+
expect(File.exist?(file)).to be true
|
185
193
|
end
|
186
194
|
|
187
195
|
it "logs status" do
|
196
|
+
runner.instance_variable_set("@klass", "Config")
|
188
197
|
expect(capture(:stdout) { runner.template("doc/config.rb") }).to eq(" create doc/config.rb\n")
|
189
198
|
end
|
190
199
|
|
191
200
|
it "accepts a block to change output" do
|
201
|
+
runner.instance_variable_set("@klass", "Config")
|
192
202
|
action :template, "doc/config.rb" do |content|
|
193
203
|
"OMG" + content
|
194
204
|
end
|
@@ -199,7 +209,7 @@ describe Thor::Actions do
|
|
199
209
|
action :template, "doc/config.yaml.tt"
|
200
210
|
|
201
211
|
file = File.join(destination_root, "doc/config.yaml")
|
202
|
-
expect(File.
|
212
|
+
expect(File.exist?(file)).to be true
|
203
213
|
end
|
204
214
|
end
|
205
215
|
|
@@ -215,18 +225,18 @@ describe Thor::Actions do
|
|
215
225
|
describe "#remove_file" do
|
216
226
|
it "removes the file given" do
|
217
227
|
action :remove_file, "doc/README"
|
218
|
-
expect(File.
|
228
|
+
expect(File.exist?(file)).to be false
|
219
229
|
end
|
220
230
|
|
221
231
|
it "removes directories too" do
|
222
232
|
action :remove_dir, "doc"
|
223
|
-
expect(File.
|
233
|
+
expect(File.exist?(File.join(destination_root, "doc"))).to be false
|
224
234
|
end
|
225
235
|
|
226
236
|
it "does not remove if pretending" do
|
227
237
|
runner(:pretend => true)
|
228
238
|
action :remove_file, "doc/README"
|
229
|
-
expect(File.
|
239
|
+
expect(File.exist?(file)).to be true
|
230
240
|
end
|
231
241
|
|
232
242
|
it "logs status" do
|
@@ -251,7 +261,7 @@ describe Thor::Actions do
|
|
251
261
|
end
|
252
262
|
|
253
263
|
it "accepts a block" do
|
254
|
-
action(:gsub_file, "doc/README", "__start__"){ |match| match.gsub(
|
264
|
+
action(:gsub_file, "doc/README", "__start__") { |match| match.gsub("__", "").upcase }
|
255
265
|
expect(File.binread(file)).to eq("START\nREADME\n__end__\n")
|
256
266
|
end
|
257
267
|
|
@@ -260,7 +270,7 @@ describe Thor::Actions do
|
|
260
270
|
end
|
261
271
|
|
262
272
|
it "does not log status if required" do
|
263
|
-
expect(action(:gsub_file, file, "__", :verbose => false){ |match| match * 2 }).to be_empty
|
273
|
+
expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty
|
264
274
|
end
|
265
275
|
end
|
266
276
|
|
@@ -271,7 +281,7 @@ describe Thor::Actions do
|
|
271
281
|
end
|
272
282
|
|
273
283
|
it "accepts a block" do
|
274
|
-
action(:append_to_file, "doc/README"){ "END\n" }
|
284
|
+
action(:append_to_file, "doc/README") { "END\n" }
|
275
285
|
expect(File.binread(file)).to eq("__start__\nREADME\n__end__\nEND\n")
|
276
286
|
end
|
277
287
|
|
@@ -287,7 +297,7 @@ describe Thor::Actions do
|
|
287
297
|
end
|
288
298
|
|
289
299
|
it "accepts a block" do
|
290
|
-
action(:prepend_to_file, "doc/README"){ "START\n" }
|
300
|
+
action(:prepend_to_file, "doc/README") { "START\n" }
|
291
301
|
expect(File.binread(file)).to eq("START\n__start__\nREADME\n__end__\n")
|
292
302
|
end
|
293
303
|
|
@@ -307,7 +317,7 @@ describe Thor::Actions do
|
|
307
317
|
end
|
308
318
|
|
309
319
|
it "accepts a block" do
|
310
|
-
action(:inject_into_class, "application.rb", Application){ " filter_parameters :password\n" }
|
320
|
+
action(:inject_into_class, "application.rb", Application) { " filter_parameters :password\n" }
|
311
321
|
expect(File.binread(file)).to eq("class Application < Base\n filter_parameters :password\nend\n")
|
312
322
|
end
|
313
323
|
|