thor 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +12 -8
- data/lib/thor.rb +79 -10
- data/lib/thor/actions.rb +13 -13
- data/lib/thor/actions/directory.rb +29 -10
- data/lib/thor/actions/file_manipulation.rb +8 -2
- data/lib/thor/base.rb +24 -11
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +5 -0
- data/lib/thor/group.rb +5 -5
- data/lib/thor/parser/options.rb +63 -25
- data/lib/thor/rake_compat.rb +3 -2
- data/lib/thor/runner.rb +1 -1
- data/lib/thor/shell/basic.rb +16 -16
- data/lib/thor/shell/color.rb +9 -9
- data/lib/thor/shell/html.rb +9 -9
- data/lib/thor/task.rb +2 -2
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +30 -30
- data/spec/actions/create_link_spec.rb +12 -12
- data/spec/actions/directory_spec.rb +34 -27
- data/spec/actions/empty_directory_spec.rb +16 -16
- data/spec/actions/file_manipulation_spec.rb +62 -50
- data/spec/actions/inject_into_file_spec.rb +18 -18
- data/spec/actions_spec.rb +56 -56
- data/spec/base_spec.rb +69 -69
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +19 -14
- data/spec/core_ext/ordered_hash_spec.rb +29 -29
- data/spec/exit_condition_spec.rb +3 -3
- data/spec/fixtures/preserve/script.sh +3 -0
- data/spec/fixtures/script.thor +5 -0
- data/spec/group_spec.rb +55 -55
- data/spec/invocation_spec.rb +26 -26
- data/spec/parser/argument_spec.rb +12 -12
- data/spec/parser/arguments_spec.rb +12 -12
- data/spec/parser/option_spec.rb +47 -47
- data/spec/parser/options_spec.rb +137 -72
- data/spec/rake_compat_spec.rb +11 -11
- data/spec/register_spec.rb +70 -8
- data/spec/runner_spec.rb +38 -38
- data/spec/shell/basic_spec.rb +49 -37
- data/spec/shell/color_spec.rb +13 -13
- data/spec/shell/html_spec.rb +3 -3
- data/spec/shell_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -0
- data/spec/task_spec.rb +11 -11
- data/spec/thor_spec.rb +161 -91
- data/spec/util_spec.rb +42 -42
- data/thor.gemspec +1 -7
- metadata +8 -118
- data/lib/thor/core_ext/dir_escape.rb +0 -0
data/spec/register_spec.rb
CHANGED
@@ -54,6 +54,34 @@ class CompatibleWith19Plugin < ClassOptionGroupPlugin
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
class PluginWithDefault < Thor
|
58
|
+
desc "say MSG", "print MSG"
|
59
|
+
def say(msg)
|
60
|
+
puts msg
|
61
|
+
end
|
62
|
+
|
63
|
+
default_task :say
|
64
|
+
end
|
65
|
+
|
66
|
+
class PluginWithDefaultMultipleArguments < Thor
|
67
|
+
desc "say MSG [MSG]", "print multiple messages"
|
68
|
+
def say(*args)
|
69
|
+
puts args
|
70
|
+
end
|
71
|
+
|
72
|
+
default_task :say
|
73
|
+
end
|
74
|
+
|
75
|
+
class PluginWithDefaultTaskAndDeclaredArgument < Thor
|
76
|
+
desc "say MSG [MSG]", "print multiple messages"
|
77
|
+
argument :msg
|
78
|
+
def say
|
79
|
+
puts msg
|
80
|
+
end
|
81
|
+
|
82
|
+
default_task :say
|
83
|
+
end
|
84
|
+
|
57
85
|
BoringVendorProvidedCLI.register(
|
58
86
|
ExcitingPluginCLI,
|
59
87
|
"exciting",
|
@@ -79,15 +107,49 @@ BoringVendorProvidedCLI.register(
|
|
79
107
|
"zoo [-w animal]",
|
80
108
|
"Shows a provided animal or just zebra")
|
81
109
|
|
110
|
+
BoringVendorProvidedCLI.register(
|
111
|
+
PluginWithDefault,
|
112
|
+
'say',
|
113
|
+
'say message',
|
114
|
+
'subcommands ftw')
|
115
|
+
|
116
|
+
BoringVendorProvidedCLI.register(
|
117
|
+
PluginWithDefaultMultipleArguments,
|
118
|
+
'say_multiple',
|
119
|
+
'say message',
|
120
|
+
'subcommands ftw')
|
121
|
+
|
122
|
+
BoringVendorProvidedCLI.register(
|
123
|
+
PluginWithDefaultTaskAndDeclaredArgument,
|
124
|
+
'say_argument',
|
125
|
+
'say message',
|
126
|
+
'subcommands ftw')
|
127
|
+
|
82
128
|
describe ".register-ing a Thor subclass" do
|
83
129
|
it "registers the plugin as a subcommand" do
|
84
130
|
fireworks_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[exciting fireworks]) }
|
85
|
-
fireworks_output.
|
131
|
+
expect(fireworks_output).to eq("kaboom!\n")
|
86
132
|
end
|
87
133
|
|
88
134
|
it "includes the plugin's usage in the help" do
|
89
135
|
help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) }
|
90
|
-
help_output.
|
136
|
+
expect(help_output).to include('do exciting things')
|
137
|
+
end
|
138
|
+
|
139
|
+
it "invokes the default task correctly" do
|
140
|
+
output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[say hello]) }
|
141
|
+
expect(output).to include("hello")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "invokes the default task correctly with multiple args" do
|
145
|
+
output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[say_multiple hello adam]) }
|
146
|
+
expect(output).to include("hello")
|
147
|
+
expect(output).to include("adam")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "invokes the default task correctly with a declared argument" do
|
151
|
+
output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[say_argument hello]) }
|
152
|
+
expect(output).to include("hello")
|
91
153
|
end
|
92
154
|
|
93
155
|
context "when $thor_runner is false" do
|
@@ -95,7 +157,7 @@ describe ".register-ing a Thor subclass" do
|
|
95
157
|
begin
|
96
158
|
$thor_runner = false
|
97
159
|
help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[exciting]) }
|
98
|
-
help_output.
|
160
|
+
expect(help_output).to include('thor exciting_plugin_c_l_i fireworks')
|
99
161
|
ensure
|
100
162
|
$thor_runner = true
|
101
163
|
end
|
@@ -105,12 +167,12 @@ describe ".register-ing a Thor subclass" do
|
|
105
167
|
context "when hidden" do
|
106
168
|
it "omits the hidden plugin's usage from the help" do
|
107
169
|
help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[help]) }
|
108
|
-
help_output.
|
170
|
+
expect(help_output).not_to include('secret stuff')
|
109
171
|
end
|
110
172
|
|
111
173
|
it "registers the plugin as a subcommand" do
|
112
174
|
secret_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[secret squirrel]) }
|
113
|
-
secret_output.
|
175
|
+
expect(secret_output).to eq("I love nuts\n")
|
114
176
|
end
|
115
177
|
end
|
116
178
|
end
|
@@ -118,18 +180,18 @@ end
|
|
118
180
|
describe ".register-ing a Thor::Group subclass" do
|
119
181
|
it "registers the group as a single command" do
|
120
182
|
group_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[groupwork]) }
|
121
|
-
group_output.
|
183
|
+
expect(group_output).to eq("part one\npart two\n")
|
122
184
|
end
|
123
185
|
end
|
124
186
|
|
125
187
|
describe "1.8 and 1.9 syntax compatibility" do
|
126
188
|
it "is compatible with both 1.8 and 1.9 syntax w/o task options" do
|
127
189
|
group_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[zoo]) }
|
128
|
-
group_output.
|
190
|
+
expect(group_output).to match(/zebra/)
|
129
191
|
end
|
130
192
|
|
131
193
|
it "is compatible with both 1.8 and 1.9 syntax w/task options" do
|
132
194
|
group_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w[zoo -w lion]) }
|
133
|
-
group_output.
|
195
|
+
expect(group_output).to match(/lion/)
|
134
196
|
end
|
135
197
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -14,41 +14,41 @@ describe Thor::Runner do
|
|
14
14
|
|
15
15
|
describe "#help" do
|
16
16
|
it "shows information about Thor::Runner itself" do
|
17
|
-
capture(:stdout){ Thor::Runner.start(["help"]) }.
|
17
|
+
expect(capture(:stdout) { Thor::Runner.start(["help"]) }).to match(/List the available thor tasks/)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "shows information about an specific Thor::Runner task" do
|
21
|
-
content = capture(:stdout){ Thor::Runner.start(["help", "list"]) }
|
22
|
-
content.
|
23
|
-
content.
|
21
|
+
content = capture(:stdout) { Thor::Runner.start(["help", "list"]) }
|
22
|
+
expect(content).to match(/List the available thor tasks/)
|
23
|
+
expect(content).not_to match(/help \[TASK\]/)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "shows information about a specific Thor class" do
|
27
|
-
content = capture(:stdout){ Thor::Runner.start(["help", "my_script"]) }
|
28
|
-
content.
|
27
|
+
content = capture(:stdout) { Thor::Runner.start(["help", "my_script"]) }
|
28
|
+
expect(content).to match(/zoo\s+# zoo around/m)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "shows information about an specific task from an specific Thor class" do
|
32
|
-
content = capture(:stdout){ Thor::Runner.start(["help", "my_script:zoo"]) }
|
33
|
-
content.
|
34
|
-
content.
|
32
|
+
content = capture(:stdout) { Thor::Runner.start(["help", "my_script:zoo"]) }
|
33
|
+
expect(content).to match(/zoo around/)
|
34
|
+
expect(content).not_to match(/help \[TASK\]/)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "shows information about a specific Thor group class" do
|
38
|
-
content = capture(:stdout){ Thor::Runner.start(["help", "my_counter"]) }
|
39
|
-
content.
|
38
|
+
content = capture(:stdout) { Thor::Runner.start(["help", "my_counter"]) }
|
39
|
+
expect(content).to match(/my_counter N/)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "raises error if a class/task cannot be found" do
|
43
43
|
content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
|
44
|
-
content.strip.
|
44
|
+
expect(content.strip).to eq('Could not find task "unknown" in "default" namespace.')
|
45
45
|
end
|
46
46
|
|
47
47
|
it "raises error if a class/task cannot be found for a setup without thorfiles" do
|
48
48
|
when_no_thorfiles_exist do
|
49
49
|
Thor::Runner.should_receive :exit
|
50
50
|
content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
|
51
|
-
content.strip.
|
51
|
+
expect(content.strip).to eq('Could not find task "unknown".')
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -56,38 +56,38 @@ describe Thor::Runner do
|
|
56
56
|
describe "#start" do
|
57
57
|
it "invokes a task from Thor::Runner" do
|
58
58
|
ARGV.replace ["list"]
|
59
|
-
capture(:stdout){ Thor::Runner.start }.
|
59
|
+
expect(capture(:stdout) { Thor::Runner.start }).to match(/my_counter N/)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "invokes a task from a specific Thor class" do
|
63
63
|
ARGV.replace ["my_script:zoo"]
|
64
|
-
Thor::Runner.start.
|
64
|
+
expect(Thor::Runner.start).to be_true
|
65
65
|
end
|
66
66
|
|
67
67
|
it "invokes the default task from a specific Thor class if none is specified" do
|
68
68
|
ARGV.replace ["my_script"]
|
69
|
-
Thor::Runner.start.
|
69
|
+
expect(Thor::Runner.start).to eq("default task")
|
70
70
|
end
|
71
71
|
|
72
72
|
it "forwads arguments to the invoked task" do
|
73
73
|
ARGV.replace ["my_script:animal", "horse"]
|
74
|
-
Thor::Runner.start.
|
74
|
+
expect(Thor::Runner.start).to eq(["horse"])
|
75
75
|
end
|
76
76
|
|
77
77
|
it "invokes tasks through shortcuts" do
|
78
78
|
ARGV.replace ["my_script", "-T", "horse"]
|
79
|
-
Thor::Runner.start.
|
79
|
+
expect(Thor::Runner.start).to eq(["horse"])
|
80
80
|
end
|
81
81
|
|
82
82
|
it "invokes a Thor::Group" do
|
83
83
|
ARGV.replace ["my_counter", "1", "2", "--third", "3"]
|
84
|
-
Thor::Runner.start.
|
84
|
+
expect(Thor::Runner.start).to eq([1, 2, 3])
|
85
85
|
end
|
86
86
|
|
87
87
|
it "raises an error if class/task can't be found" do
|
88
88
|
ARGV.replace ["unknown"]
|
89
89
|
content = capture(:stderr){ Thor::Runner.start }
|
90
|
-
content.strip.
|
90
|
+
expect(content.strip).to eq('Could not find task "unknown" in "default" namespace.')
|
91
91
|
end
|
92
92
|
|
93
93
|
it "raises an error if class/task can't be found in a setup without thorfiles" do
|
@@ -95,24 +95,24 @@ describe Thor::Runner do
|
|
95
95
|
ARGV.replace ["unknown"]
|
96
96
|
Thor::Runner.should_receive :exit
|
97
97
|
content = capture(:stderr){ Thor::Runner.start }
|
98
|
-
content.strip.
|
98
|
+
expect(content.strip).to eq('Could not find task "unknown".')
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
it "does not swallow NoMethodErrors that occur inside the called method" do
|
103
103
|
ARGV.replace ["my_script:call_unexistent_method"]
|
104
|
-
|
104
|
+
expect{ Thor::Runner.start }.to raise_error(NoMethodError)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "does not swallow Thor::Group InvocationError" do
|
108
108
|
ARGV.replace ["whiny_generator"]
|
109
|
-
|
109
|
+
expect{ Thor::Runner.start }.to raise_error(ArgumentError, /thor wrong_arity takes 1 argument, but it should not/)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "does not swallow Thor InvocationError" do
|
113
113
|
ARGV.replace ["my_script:animal"]
|
114
114
|
content = capture(:stderr) { Thor::Runner.start }
|
115
|
-
content.strip.
|
115
|
+
expect(content.strip).to eq('thor animal requires at least 1 argument: "thor my_script:animal TYPE".')
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -139,53 +139,53 @@ describe Thor::Runner do
|
|
139
139
|
it "gives a list of the available tasks" do
|
140
140
|
ARGV.replace ["list"]
|
141
141
|
content = capture(:stdout) { Thor::Runner.start }
|
142
|
-
content.
|
142
|
+
expect(content).to match(/amazing:describe NAME\s+# say that someone is amazing/m)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "gives a list of the available Thor::Group classes" do
|
146
146
|
ARGV.replace ["list"]
|
147
|
-
capture(:stdout) { Thor::Runner.start }.
|
147
|
+
expect(capture(:stdout) { Thor::Runner.start }).to match(/my_counter N/)
|
148
148
|
end
|
149
149
|
|
150
150
|
it "can filter a list of the available tasks by --group" do
|
151
151
|
ARGV.replace ["list", "--group", "standard"]
|
152
|
-
capture(:stdout) { Thor::Runner.start }.
|
152
|
+
expect(capture(:stdout) { Thor::Runner.start }).to match(/amazing:describe NAME/)
|
153
153
|
ARGV.replace []
|
154
|
-
capture(:stdout) { Thor::Runner.start }.
|
154
|
+
expect(capture(:stdout) { Thor::Runner.start }).not_to match(/my_script:animal TYPE/)
|
155
155
|
ARGV.replace ["list", "--group", "script"]
|
156
|
-
capture(:stdout) { Thor::Runner.start }.
|
156
|
+
expect(capture(:stdout) { Thor::Runner.start }).to match(/my_script:animal TYPE/)
|
157
157
|
end
|
158
158
|
|
159
159
|
it "can skip all filters to show all tasks using --all" do
|
160
160
|
ARGV.replace ["list", "--all"]
|
161
161
|
content = capture(:stdout) { Thor::Runner.start }
|
162
|
-
content.
|
163
|
-
content.
|
162
|
+
expect(content).to match(/amazing:describe NAME/)
|
163
|
+
expect(content).to match(/my_script:animal TYPE/)
|
164
164
|
end
|
165
165
|
|
166
166
|
it "doesn't list superclass tasks in the subclass" do
|
167
167
|
ARGV.replace ["list"]
|
168
|
-
capture(:stdout) { Thor::Runner.start }.
|
168
|
+
expect(capture(:stdout) { Thor::Runner.start }).not_to match(/amazing:help/)
|
169
169
|
end
|
170
170
|
|
171
171
|
it "presents tasks in the default namespace with an empty namespace" do
|
172
172
|
ARGV.replace ["list"]
|
173
|
-
capture(:stdout) { Thor::Runner.start }.
|
173
|
+
expect(capture(:stdout) { Thor::Runner.start }).to match(/^thor :cow\s+# prints 'moo'/m)
|
174
174
|
end
|
175
175
|
|
176
176
|
it "runs tasks with an empty namespace from the default namespace" do
|
177
177
|
ARGV.replace [":task_conflict"]
|
178
|
-
capture(:stdout) { Thor::Runner.start }.
|
178
|
+
expect(capture(:stdout) { Thor::Runner.start }).to eq("task\n")
|
179
179
|
end
|
180
180
|
|
181
181
|
it "runs groups even when there is a task with the same name" do
|
182
182
|
ARGV.replace ["task_conflict"]
|
183
|
-
capture(:stdout) { Thor::Runner.start }.
|
183
|
+
expect(capture(:stdout) { Thor::Runner.start }).to eq("group\n")
|
184
184
|
end
|
185
185
|
|
186
186
|
it "runs tasks with no colon in the default namespace" do
|
187
187
|
ARGV.replace ["cow"]
|
188
|
-
capture(:stdout) { Thor::Runner.start }.
|
188
|
+
expect(capture(:stdout) { Thor::Runner.start }).to eq("moo\n")
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -207,8 +207,8 @@ describe Thor::Runner do
|
|
207
207
|
|
208
208
|
it "displays the modules installed in a pretty way" do
|
209
209
|
stdout = capture(:stdout) { Thor::Runner.start(["installed"]) }
|
210
|
-
stdout.
|
211
|
-
stdout.
|
210
|
+
expect(stdout).to match(/random\s*amazing/)
|
211
|
+
expect(stdout).to match(/amazing:describe NAME\s+# say that someone is amazing/m)
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
data/spec/shell/basic_spec.rb
CHANGED
@@ -10,10 +10,10 @@ describe Thor::Shell::Basic do
|
|
10
10
|
describe "#padding" do
|
11
11
|
it "cannot be set to below zero" do
|
12
12
|
shell.padding = 10
|
13
|
-
shell.padding.
|
13
|
+
expect(shell.padding).to eq(10)
|
14
14
|
|
15
15
|
shell.padding = -1
|
16
|
-
shell.padding.
|
16
|
+
expect(shell.padding).to eq(0)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,20 +21,27 @@ describe Thor::Shell::Basic do
|
|
21
21
|
it "prints a message to the user and gets the response" do
|
22
22
|
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
23
23
|
$stdin.should_receive(:gets).and_return('Sure')
|
24
|
-
shell.ask("Should I overwrite it?").
|
24
|
+
expect(shell.ask("Should I overwrite it?")).to eq("Sure")
|
25
25
|
end
|
26
26
|
|
27
|
+
it "prints a message and returns nil if EOF is sent to stdin" do
|
28
|
+
$stdout.should_receive(:print).with(" ")
|
29
|
+
$stdin.should_receive(:gets).and_return(nil)
|
30
|
+
expect(shell.ask("")).to eq(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
27
34
|
it "prints a message to the user with the available options and determines the correctness of the answer" do
|
28
35
|
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ')
|
29
36
|
$stdin.should_receive(:gets).and_return('chocolate')
|
30
|
-
shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"]).
|
37
|
+
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
|
31
38
|
end
|
32
39
|
|
33
40
|
it "prints a message to the user with the available options and reasks the question after an incorrect repsonse" do
|
34
41
|
$stdout.should_receive(:print).with('What\'s your favorite Neopolitan flavor? ["strawberry", "chocolate", "vanilla"] ').twice
|
35
42
|
$stdout.should_receive(:puts).with('Your response must be one of: ["strawberry", "chocolate", "vanilla"]. Please try again.')
|
36
43
|
$stdin.should_receive(:gets).and_return('moose tracks', 'chocolate')
|
37
|
-
shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"]).
|
44
|
+
expect(shell.ask("What's your favorite Neopolitan flavor?", :limited_to => ["strawberry", "chocolate", "vanilla"])).to eq("chocolate")
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
@@ -42,11 +49,11 @@ describe Thor::Shell::Basic do
|
|
42
49
|
it "asks the user and returns true if the user replies yes" do
|
43
50
|
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
44
51
|
$stdin.should_receive(:gets).and_return('y')
|
45
|
-
shell.yes?("Should I overwrite it?").
|
52
|
+
expect(shell.yes?("Should I overwrite it?")).to be_true
|
46
53
|
|
47
54
|
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
48
55
|
$stdin.should_receive(:gets).and_return('n')
|
49
|
-
shell.yes?("Should I overwrite it?").
|
56
|
+
expect(shell.yes?("Should I overwrite it?")).not_to be_true
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
@@ -54,11 +61,11 @@ describe Thor::Shell::Basic do
|
|
54
61
|
it "asks the user and returns true if the user replies no" do
|
55
62
|
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
56
63
|
$stdin.should_receive(:gets).and_return('n')
|
57
|
-
shell.no?("Should I overwrite it?").
|
64
|
+
expect(shell.no?("Should I overwrite it?")).to be_true
|
58
65
|
|
59
66
|
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
60
67
|
$stdin.should_receive(:gets).and_return('Yes')
|
61
|
-
shell.no?("Should I overwrite it?").
|
68
|
+
expect(shell.no?("Should I overwrite it?")).to be_false
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
@@ -73,6 +80,11 @@ describe Thor::Shell::Basic do
|
|
73
80
|
shell.say("Running... ")
|
74
81
|
end
|
75
82
|
|
83
|
+
it "does not use a new line with whitespace+newline embedded" do
|
84
|
+
$stdout.should_receive(:puts).with("It's \nRunning...")
|
85
|
+
shell.say("It's \nRunning...")
|
86
|
+
end
|
87
|
+
|
76
88
|
it "prints a message to the user without new line" do
|
77
89
|
$stdout.should_receive(:print).with("Running...")
|
78
90
|
shell.say("Running...", nil, false)
|
@@ -127,8 +139,8 @@ describe Thor::Shell::Basic do
|
|
127
139
|
end
|
128
140
|
|
129
141
|
it "prints in columns" do
|
130
|
-
content = capture(:stdout){ shell.print_in_columns(@array) }
|
131
|
-
content.rstrip.
|
142
|
+
content = capture(:stdout) { shell.print_in_columns(@array) }
|
143
|
+
expect(content.rstrip).to eq("1234567890 a b c d e")
|
132
144
|
end
|
133
145
|
end
|
134
146
|
|
@@ -141,8 +153,8 @@ describe Thor::Shell::Basic do
|
|
141
153
|
end
|
142
154
|
|
143
155
|
it "prints a table" do
|
144
|
-
content = capture(:stdout){ shell.print_table(@table) }
|
145
|
-
content.
|
156
|
+
content = capture(:stdout) { shell.print_table(@table) }
|
157
|
+
expect(content).to eq(<<-TABLE)
|
146
158
|
abc #123 first three
|
147
159
|
#0 empty
|
148
160
|
xyz #786 last three
|
@@ -150,8 +162,8 @@ TABLE
|
|
150
162
|
end
|
151
163
|
|
152
164
|
it "prints a table with indentation" do
|
153
|
-
content = capture(:stdout){ shell.print_table(@table, :indent => 2) }
|
154
|
-
content.
|
165
|
+
content = capture(:stdout) { shell.print_table(@table, :indent => 2) }
|
166
|
+
expect(content).to eq(<<-TABLE)
|
155
167
|
abc #123 first three
|
156
168
|
#0 empty
|
157
169
|
xyz #786 last three
|
@@ -162,8 +174,8 @@ TABLE
|
|
162
174
|
@table << ["def", "#456", "Lançam foo bar"]
|
163
175
|
@table << ["ghi", "#789", "بالله عليكم"]
|
164
176
|
shell.should_receive(:terminal_width).and_return(20)
|
165
|
-
content = capture(:stdout){ shell.print_table(@table, :indent => 2, :truncate => true) }
|
166
|
-
content.
|
177
|
+
content = capture(:stdout) { shell.print_table(@table, :indent => 2, :truncate => true) }
|
178
|
+
expect(content).to eq(<<-TABLE)
|
167
179
|
abc #123 firs...
|
168
180
|
#0 empty
|
169
181
|
xyz #786 last...
|
@@ -173,8 +185,8 @@ TABLE
|
|
173
185
|
end
|
174
186
|
|
175
187
|
it "honors the colwidth option" do
|
176
|
-
content = capture(:stdout){ shell.print_table(@table, :colwidth => 10)}
|
177
|
-
content.
|
188
|
+
content = capture(:stdout) { shell.print_table(@table, :colwidth => 10)}
|
189
|
+
expect(content).to eq(<<-TABLE)
|
178
190
|
abc #123 first three
|
179
191
|
#0 empty
|
180
192
|
xyz #786 last three
|
@@ -183,8 +195,8 @@ TABLE
|
|
183
195
|
|
184
196
|
it "prints tables with implicit columns" do
|
185
197
|
2.times { @table.first.pop }
|
186
|
-
content = capture(:stdout){ shell.print_table(@table) }
|
187
|
-
content.
|
198
|
+
content = capture(:stdout) { shell.print_table(@table) }
|
199
|
+
expect(content).to eq(<<-TABLE)
|
188
200
|
abc
|
189
201
|
#0 empty
|
190
202
|
xyz #786 last three
|
@@ -196,8 +208,8 @@ TABLE
|
|
196
208
|
["Name", "Number", "Color"],
|
197
209
|
["Erik", 1, "green"]
|
198
210
|
]
|
199
|
-
content = capture(:stdout){ shell.print_table(table) }
|
200
|
-
content.
|
211
|
+
content = capture(:stdout) { shell.print_table(table) }
|
212
|
+
expect(content).to eq(<<-TABLE)
|
201
213
|
Name Number Color
|
202
214
|
Erik 1 green
|
203
215
|
TABLE
|
@@ -208,8 +220,8 @@ TABLE
|
|
208
220
|
["Name", "Number"],
|
209
221
|
["Erik", 1]
|
210
222
|
]
|
211
|
-
content = capture(:stdout){ shell.print_table(table) }
|
212
|
-
content.
|
223
|
+
content = capture(:stdout) { shell.print_table(table) }
|
224
|
+
expect(content).to eq(<<-TABLE)
|
213
225
|
Name Number
|
214
226
|
Erik 1
|
215
227
|
TABLE
|
@@ -220,8 +232,8 @@ TABLE
|
|
220
232
|
["Name", "Number", "Color"],
|
221
233
|
["Erik", 1234567890123, "green"]
|
222
234
|
]
|
223
|
-
content = capture(:stdout){ shell.print_table(table) }
|
224
|
-
content.
|
235
|
+
content = capture(:stdout) { shell.print_table(table) }
|
236
|
+
expect(content).to eq(<<-TABLE)
|
225
237
|
Name Number Color
|
226
238
|
Erik 1234567890123 green
|
227
239
|
TABLE
|
@@ -238,27 +250,27 @@ TABLE
|
|
238
250
|
it "returns true if the user choose default option" do
|
239
251
|
$stdout.stub!(:print)
|
240
252
|
$stdin.should_receive(:gets).and_return('')
|
241
|
-
shell.file_collision('foo').
|
253
|
+
expect(shell.file_collision('foo')).to be_true
|
242
254
|
end
|
243
255
|
|
244
256
|
it "returns false if the user choose no" do
|
245
257
|
$stdout.stub!(:print)
|
246
258
|
$stdin.should_receive(:gets).and_return('n')
|
247
|
-
shell.file_collision('foo').
|
259
|
+
expect(shell.file_collision('foo')).to be_false
|
248
260
|
end
|
249
261
|
|
250
262
|
it "returns true if the user choose yes" do
|
251
263
|
$stdout.stub!(:print)
|
252
264
|
$stdin.should_receive(:gets).and_return('y')
|
253
|
-
shell.file_collision('foo').
|
265
|
+
expect(shell.file_collision('foo')).to be_true
|
254
266
|
end
|
255
267
|
|
256
268
|
it "shows help usage if the user choose help" do
|
257
269
|
$stdout.stub!(:print)
|
258
270
|
$stdin.should_receive(:gets).and_return('h')
|
259
271
|
$stdin.should_receive(:gets).and_return('n')
|
260
|
-
help = capture(:stdout){ shell.file_collision('foo') }
|
261
|
-
help.
|
272
|
+
help = capture(:stdout) { shell.file_collision('foo') }
|
273
|
+
expect(help).to match(/h \- help, show this help/)
|
262
274
|
end
|
263
275
|
|
264
276
|
it "quits if the user choose quit" do
|
@@ -266,19 +278,19 @@ TABLE
|
|
266
278
|
$stdout.should_receive(:puts).with('Aborting...')
|
267
279
|
$stdin.should_receive(:gets).and_return('q')
|
268
280
|
|
269
|
-
|
281
|
+
expect {
|
270
282
|
shell.file_collision('foo')
|
271
|
-
}.
|
283
|
+
}.to raise_error(SystemExit)
|
272
284
|
end
|
273
285
|
|
274
286
|
it "always returns true if the user choose always" do
|
275
287
|
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
|
276
288
|
$stdin.should_receive(:gets).and_return('a')
|
277
289
|
|
278
|
-
shell.file_collision('foo').
|
290
|
+
expect(shell.file_collision('foo')).to be_true
|
279
291
|
|
280
292
|
$stdout.should_not_receive(:print)
|
281
|
-
shell.file_collision('foo').
|
293
|
+
expect(shell.file_collision('foo')).to be_true
|
282
294
|
end
|
283
295
|
|
284
296
|
describe "when a block is given" do
|
@@ -293,7 +305,7 @@ TABLE
|
|
293
305
|
$stdin.should_receive(:gets).and_return('d')
|
294
306
|
$stdin.should_receive(:gets).and_return('n')
|
295
307
|
shell.should_receive(:system).with(/diff -u/)
|
296
|
-
capture(:stdout){ shell.file_collision('foo'){ } }
|
308
|
+
capture(:stdout) { shell.file_collision('foo'){ } }
|
297
309
|
end
|
298
310
|
end
|
299
311
|
end
|