thor 0.12.0 → 0.12.3
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/CHANGELOG.rdoc +3 -5
- data/Thorfile +2 -1
- data/bin/thor +1 -0
- data/lib/thor/actions/create_file.rb +2 -2
- data/lib/thor/actions/directory.rb +2 -4
- data/lib/thor/actions/file_manipulation.rb +10 -6
- data/lib/thor/actions/inject_into_file.rb +1 -1
- data/lib/thor/actions.rb +6 -5
- data/lib/thor/base.rb +30 -32
- data/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/thor/group.rb +44 -36
- data/lib/thor/runner.rb +44 -40
- data/lib/thor/shell/basic.rb +49 -29
- data/lib/thor/shell/color.rb +1 -1
- data/lib/thor/shell.rb +1 -1
- data/lib/thor/task.rb +32 -43
- data/lib/thor/util.rb +4 -22
- data/lib/thor/version.rb +1 -1
- data/lib/thor.rb +43 -43
- data/spec/actions/create_file_spec.rb +7 -7
- data/spec/actions/directory_spec.rb +5 -4
- data/spec/actions/file_manipulation_spec.rb +29 -16
- data/spec/actions_spec.rb +14 -13
- data/spec/base_spec.rb +1 -1
- data/spec/fixtures/bundle/main.thor +1 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/group.thor +83 -0
- data/spec/fixtures/invoke.thor +112 -0
- data/spec/fixtures/script.thor +130 -0
- data/spec/fixtures/task.thor +10 -0
- data/spec/group_spec.rb +1 -7
- data/spec/runner_spec.rb +35 -39
- data/spec/shell/basic_spec.rb +56 -62
- data/spec/shell/color_spec.rb +6 -6
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/task_spec.rb +14 -32
- data/spec/thor_spec.rb +21 -22
- data/spec/util_spec.rb +7 -31
- metadata +28 -19
data/spec/shell/basic_spec.rb
CHANGED
|
@@ -17,107 +17,85 @@ describe Thor::Shell::Basic do
|
|
|
17
17
|
|
|
18
18
|
describe "#ask" do
|
|
19
19
|
it "prints a message to the user and gets the response" do
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
|
21
|
+
$stdin.should_receive(:gets).and_return('Sure')
|
|
22
22
|
shell.ask("Should I overwrite it?").must == "Sure"
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
describe "#yes?" do
|
|
27
27
|
it "asks the user and returns true if the user replies yes" do
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
|
29
|
+
$stdin.should_receive(:gets).and_return('y')
|
|
30
30
|
shell.yes?("Should I overwrite it?").must be_true
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
|
33
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
34
34
|
shell.yes?("Should I overwrite it?").must_not be_true
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
describe "#no?" do
|
|
39
39
|
it "asks the user and returns true if the user replies no" do
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
|
41
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
42
42
|
shell.no?("Should I overwrite it?").must be_true
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
$stdout.should_receive(:print).with("Should I overwrite it? ")
|
|
45
|
+
$stdin.should_receive(:gets).and_return('Yes')
|
|
46
46
|
shell.no?("Should I overwrite it?").must be_false
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
describe "#say" do
|
|
51
51
|
it "prints a message to the user" do
|
|
52
|
-
|
|
52
|
+
$stdout.should_receive(:puts).with("Running...")
|
|
53
53
|
shell.say("Running...")
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "prints a message to the user without new line if it ends with a whitespace" do
|
|
57
|
-
|
|
57
|
+
$stdout.should_receive(:print).with("Running... ")
|
|
58
58
|
shell.say("Running... ")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "prints a message to the user without new line" do
|
|
62
|
-
|
|
62
|
+
$stdout.should_receive(:print).with("Running...")
|
|
63
63
|
shell.say("Running...", nil, false)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
describe "#say_status" do
|
|
68
68
|
it "prints a message to the user with status" do
|
|
69
|
-
|
|
69
|
+
$stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
|
|
70
70
|
shell.say_status(:create, "~/.thor/task.thor")
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "always use new line" do
|
|
74
|
-
|
|
74
|
+
$stdout.should_receive(:puts).with(" create ")
|
|
75
75
|
shell.say_status(:create, "")
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "does not print a message if base is set to quiet" do
|
|
79
79
|
base = MyCounter.new [1,2]
|
|
80
|
-
|
|
80
|
+
base.should_receive(:options).and_return(:quiet => true)
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
$stdout.should_not_receive(:puts)
|
|
83
83
|
shell.base = base
|
|
84
84
|
shell.say_status(:created, "~/.thor/task.thor")
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
it "does not print a message if log status is set to false" do
|
|
88
|
-
|
|
88
|
+
$stdout.should_not_receive(:puts)
|
|
89
89
|
shell.say_status(:created, "~/.thor/task.thor", false)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
it "uses padding to set messages left margin" do
|
|
93
93
|
shell.padding = 2
|
|
94
|
-
|
|
94
|
+
$stdout.should_receive(:puts).with(" create ~/.thor/task.thor")
|
|
95
95
|
shell.say_status(:create, "~/.thor/task.thor")
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
describe "#print_list" do
|
|
100
|
-
before(:each) do
|
|
101
|
-
@list = ["abc", "#123", "first three"]
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "prints a list" do
|
|
105
|
-
content = capture(:stdout){ shell.print_list(@list) }
|
|
106
|
-
content.must == <<-LIST
|
|
107
|
-
abc
|
|
108
|
-
#123
|
|
109
|
-
first three
|
|
110
|
-
LIST
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "prints a list inline" do
|
|
114
|
-
content = capture(:stdout){ shell.print_list(@list, :mode => :inline) }
|
|
115
|
-
content.must == <<-LIST
|
|
116
|
-
abc, #123, and first three
|
|
117
|
-
LIST
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
99
|
describe "#print_table" do
|
|
122
100
|
before(:each) do
|
|
123
101
|
@table = []
|
|
@@ -141,41 +119,57 @@ TABLE
|
|
|
141
119
|
abc #123 first three
|
|
142
120
|
#0 empty
|
|
143
121
|
xyz #786 last three
|
|
122
|
+
TABLE
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "uses maximum terminal width" do
|
|
126
|
+
shell.should_receive(:terminal_width).and_return(20)
|
|
127
|
+
content = capture(:stdout){ shell.print_table(@table, :ident => 2, :truncate => true) }
|
|
128
|
+
content.must == <<-TABLE
|
|
129
|
+
abc #123 firs...
|
|
130
|
+
#0 empty
|
|
131
|
+
xyz #786 last...
|
|
144
132
|
TABLE
|
|
145
133
|
end
|
|
146
134
|
end
|
|
147
135
|
|
|
148
136
|
describe "#file_collision" do
|
|
149
137
|
it "shows a menu with options" do
|
|
150
|
-
|
|
151
|
-
|
|
138
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
|
|
139
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
152
140
|
shell.file_collision('foo')
|
|
153
141
|
end
|
|
154
142
|
|
|
143
|
+
it "returns true if the user choose default option" do
|
|
144
|
+
$stdout.stub!(:print)
|
|
145
|
+
$stdin.should_receive(:gets).and_return('')
|
|
146
|
+
shell.file_collision('foo').must be_true
|
|
147
|
+
end
|
|
148
|
+
|
|
155
149
|
it "returns false if the user choose no" do
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
$stdout.stub!(:print)
|
|
151
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
158
152
|
shell.file_collision('foo').must be_false
|
|
159
153
|
end
|
|
160
154
|
|
|
161
155
|
it "returns true if the user choose yes" do
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
$stdout.stub!(:print)
|
|
157
|
+
$stdin.should_receive(:gets).and_return('y')
|
|
164
158
|
shell.file_collision('foo').must be_true
|
|
165
159
|
end
|
|
166
160
|
|
|
167
161
|
it "shows help usage if the user choose help" do
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
$stdout.stub!(:print)
|
|
163
|
+
$stdin.should_receive(:gets).and_return('h')
|
|
164
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
171
165
|
help = capture(:stdout){ shell.file_collision('foo') }
|
|
172
166
|
help.must =~ /h \- help, show this help/
|
|
173
167
|
end
|
|
174
168
|
|
|
175
169
|
it "quits if the user choose quit" do
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
170
|
+
$stdout.stub!(:print)
|
|
171
|
+
$stdout.should_receive(:puts).with('Aborting...')
|
|
172
|
+
$stdin.should_receive(:gets).and_return('q')
|
|
179
173
|
|
|
180
174
|
lambda {
|
|
181
175
|
shell.file_collision('foo')
|
|
@@ -183,27 +177,27 @@ TABLE
|
|
|
183
177
|
end
|
|
184
178
|
|
|
185
179
|
it "always returns true if the user choose always" do
|
|
186
|
-
|
|
187
|
-
|
|
180
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqh] ')
|
|
181
|
+
$stdin.should_receive(:gets).and_return('a')
|
|
188
182
|
|
|
189
183
|
shell.file_collision('foo').must be_true
|
|
190
184
|
|
|
191
|
-
|
|
185
|
+
$stdout.should_not_receive(:print)
|
|
192
186
|
shell.file_collision('foo').must be_true
|
|
193
187
|
end
|
|
194
188
|
|
|
195
189
|
describe "when a block is given" do
|
|
196
190
|
it "displays diff options to the user" do
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
$stdout.should_receive(:print).with('Overwrite foo? (enter "h" for help) [Ynaqdh] ')
|
|
192
|
+
$stdin.should_receive(:gets).and_return('s')
|
|
199
193
|
shell.file_collision('foo'){ }
|
|
200
194
|
end
|
|
201
195
|
|
|
202
196
|
it "invokes the diff command" do
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
197
|
+
$stdout.stub!(:print)
|
|
198
|
+
$stdin.should_receive(:gets).and_return('d')
|
|
199
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
200
|
+
shell.should_receive(:system).with(/diff -u/)
|
|
207
201
|
capture(:stdout){ shell.file_collision('foo'){ } }
|
|
208
202
|
end
|
|
209
203
|
end
|
data/spec/shell/color_spec.rb
CHANGED
|
@@ -7,19 +7,19 @@ describe Thor::Shell::Color do
|
|
|
7
7
|
|
|
8
8
|
describe "#say" do
|
|
9
9
|
it "set the color if specified" do
|
|
10
|
-
|
|
10
|
+
$stdout.should_receive(:puts).with("\e[32mWow! Now we have colors!\e[0m")
|
|
11
11
|
shell.say "Wow! Now we have colors!", :green
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it "does not use a new line even with colors" do
|
|
15
|
-
|
|
15
|
+
$stdout.should_receive(:print).with("\e[32mWow! Now we have colors! \e[0m")
|
|
16
16
|
shell.say "Wow! Now we have colors! ", :green
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
describe "#say_status" do
|
|
21
21
|
it "uses color to say status" do
|
|
22
|
-
|
|
22
|
+
$stdout.should_receive(:puts).with("\e[1m\e[31m conflict\e[0m README")
|
|
23
23
|
shell.say_status :conflict, "README", :red
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -27,9 +27,9 @@ describe Thor::Shell::Color do
|
|
|
27
27
|
describe "#file_collision" do
|
|
28
28
|
describe "when a block is given" do
|
|
29
29
|
it "invokes the diff command" do
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
$stdout.stub!(:print)
|
|
31
|
+
$stdin.should_receive(:gets).and_return('d')
|
|
32
|
+
$stdin.should_receive(:gets).and_return('n')
|
|
33
33
|
|
|
34
34
|
output = capture(:stdout){ shell.file_collision('spec/fixtures/doc/README'){ "README\nEND\n" } }
|
|
35
35
|
output.must =~ /\e\[31m\- __start__\e\[0m/
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
CHANGED
|
@@ -5,9 +5,11 @@ require 'thor'
|
|
|
5
5
|
require 'stringio'
|
|
6
6
|
|
|
7
7
|
require 'rubygems'
|
|
8
|
-
require '
|
|
8
|
+
require 'rdoc'
|
|
9
9
|
require 'diff/lcs' # You need diff/lcs installed to run specs (but not to run Thor).
|
|
10
10
|
|
|
11
|
+
$thor_runner = true
|
|
12
|
+
|
|
11
13
|
# Load fixtures
|
|
12
14
|
load File.join(File.dirname(__FILE__), "fixtures", "task.thor")
|
|
13
15
|
load File.join(File.dirname(__FILE__), "fixtures", "group.thor")
|
|
@@ -25,8 +27,6 @@ Kernel.module_eval do
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
Spec::Runner.configure do |config|
|
|
28
|
-
config.mock_with :rr
|
|
29
|
-
|
|
30
30
|
def capture(stream)
|
|
31
31
|
begin
|
|
32
32
|
stream = stream.to_s
|
|
@@ -48,5 +48,5 @@ Spec::Runner.configure do |config|
|
|
|
48
48
|
File.join(File.dirname(__FILE__), 'sandbox')
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
alias silence capture
|
|
51
|
+
alias :silence :capture
|
|
52
52
|
end
|
data/spec/task_spec.rb
CHANGED
|
@@ -10,32 +10,22 @@ describe Thor::Task do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
describe "#formatted_usage" do
|
|
13
|
-
it "shows usage with options" do
|
|
14
|
-
task('foo' => true, :bar => :required).formatted_usage.must == "can_has --bar=BAR [--foo]"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
13
|
it "includes namespace within usage" do
|
|
18
|
-
stub(
|
|
19
|
-
stub(
|
|
20
|
-
task(:bar => :required).formatted_usage(Object
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "does not show options if required" do
|
|
24
|
-
stub(Object).namespace{ "foo" }
|
|
25
|
-
stub(Object).arguments{ [] }
|
|
26
|
-
task(:bar => :required).formatted_usage(Object, true, false).must == "foo:can_has"
|
|
14
|
+
Object.stub!(:namespace).and_return("foo")
|
|
15
|
+
Object.stub!(:arguments).and_return([])
|
|
16
|
+
task(:bar => :required).formatted_usage(Object).must == "foo:can_has --bar=BAR"
|
|
27
17
|
end
|
|
28
18
|
|
|
29
19
|
it "removes default from namespace" do
|
|
30
|
-
stub(
|
|
31
|
-
stub(
|
|
32
|
-
task(:bar => :required).formatted_usage(Object
|
|
20
|
+
Object.stub!(:namespace).and_return("default:foo")
|
|
21
|
+
Object.stub!(:arguments).and_return([])
|
|
22
|
+
task(:bar => :required).formatted_usage(Object).must == ":foo:can_has --bar=BAR"
|
|
33
23
|
end
|
|
34
24
|
|
|
35
25
|
it "injects arguments into usage" do
|
|
36
|
-
stub(
|
|
37
|
-
stub(
|
|
38
|
-
task(:foo =>
|
|
26
|
+
Object.stub!(:namespace).and_return("foo")
|
|
27
|
+
Object.stub!(:arguments).and_return([ Thor::Argument.new(:bar, nil, true, :string) ])
|
|
28
|
+
task(:foo => :required).formatted_usage(Object).must == "foo:can_has BAR --foo=FOO"
|
|
39
29
|
end
|
|
40
30
|
end
|
|
41
31
|
|
|
@@ -64,25 +54,17 @@ describe Thor::Task do
|
|
|
64
54
|
|
|
65
55
|
describe "#run" do
|
|
66
56
|
it "runs a task by calling a method in the given instance" do
|
|
67
|
-
mock = mock
|
|
57
|
+
mock = mock()
|
|
58
|
+
mock.should_receive(:send).with("can_has", 1, 2, 3)
|
|
68
59
|
task.run(mock, [1, 2, 3])
|
|
69
60
|
end
|
|
70
61
|
|
|
71
62
|
it "raises an error if the method to be invoked is private" do
|
|
72
|
-
mock = mock
|
|
63
|
+
mock = mock()
|
|
64
|
+
mock.should_receive(:private_methods).and_return(['can_has'])
|
|
73
65
|
lambda {
|
|
74
66
|
task.run(mock)
|
|
75
|
-
}.must raise_error(Thor::UndefinedTaskError, "the 'can_has' task of
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
describe "#short_description" do
|
|
80
|
-
it "returns the first line of the description" do
|
|
81
|
-
Thor::Task.new(:task, "I can has\ncheezburger", "can_has").short_description == "I can has"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "returns the whole description if it's one line" do
|
|
85
|
-
Thor::Task.new(:task, "I can has cheezburger", "can_has").short_description == "I can has cheezburger"
|
|
67
|
+
}.must raise_error(Thor::UndefinedTaskError, "the 'can_has' task of Spec::Mocks::Mock is private")
|
|
86
68
|
end
|
|
87
69
|
end
|
|
88
70
|
end
|
data/spec/thor_spec.rb
CHANGED
|
@@ -72,7 +72,7 @@ describe Thor do
|
|
|
72
72
|
|
|
73
73
|
describe "when :for is supplied" do
|
|
74
74
|
it "overwrites a previous defined task" do
|
|
75
|
-
capture(:stdout) { MyChildScript.start(["help"]) }.must =~ /animal KIND \
|
|
75
|
+
capture(:stdout) { MyChildScript.start(["help"]) }.must =~ /animal KIND \s+# fish around/m
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -133,7 +133,7 @@ describe Thor do
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it "raises when an exception happens within the task call" do
|
|
136
|
-
lambda { MyScript.start(["call_myself_with_wrong_arity"]) }.must raise_error
|
|
136
|
+
lambda { MyScript.start(["call_myself_with_wrong_arity", "--debug"]) }.must raise_error
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -148,25 +148,31 @@ describe Thor do
|
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "provides useful help info for the help method itself" do
|
|
151
|
-
@content.must =~ /help \[TASK\]\s+# Describe available tasks/
|
|
151
|
+
@content.must =~ /help \[TASK\]\s+# Describe available tasks/
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "provides useful help info for a method with params" do
|
|
155
|
-
@content.must =~ /animal TYPE\s+# horse around/
|
|
155
|
+
@content.must =~ /animal TYPE\s+# horse around/
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "uses the maximum terminal size to show tasks" do
|
|
159
|
+
@shell.should_receive(:terminal_width).and_return(80)
|
|
160
|
+
content = capture(:stdout){ MyScript.help(shell) }
|
|
161
|
+
content.must =~ /aaa\.\.\.$/
|
|
156
162
|
end
|
|
157
163
|
|
|
158
164
|
it "provides description for tasks from classes in the same namespace" do
|
|
159
|
-
@content.must =~ /baz\s+# do some bazing/
|
|
165
|
+
@content.must =~ /baz\s+# do some bazing/
|
|
160
166
|
end
|
|
161
167
|
|
|
162
168
|
it "shows superclass tasks" do
|
|
163
169
|
content = capture(:stdout){ MyChildScript.help(shell) }
|
|
164
|
-
content.must =~ /foo BAR \
|
|
170
|
+
content.must =~ /foo BAR \s+# do some fooing/
|
|
165
171
|
end
|
|
166
172
|
|
|
167
173
|
it "shows class options information" do
|
|
168
174
|
content = capture(:stdout){ MyChildScript.help(shell) }
|
|
169
|
-
content.must =~ /
|
|
175
|
+
content.must =~ /Options\:/
|
|
170
176
|
content.must =~ /\[\-\-param=N\]/
|
|
171
177
|
end
|
|
172
178
|
|
|
@@ -178,11 +184,11 @@ describe Thor do
|
|
|
178
184
|
|
|
179
185
|
describe "for a specific task" do
|
|
180
186
|
it "provides full help info when talking about a specific task" do
|
|
181
|
-
capture(:stdout) { MyScript.
|
|
187
|
+
capture(:stdout) { MyScript.task_help(shell, "foo") }.must == <<END
|
|
182
188
|
Usage:
|
|
183
|
-
foo BAR
|
|
189
|
+
thor my_script:foo BAR
|
|
184
190
|
|
|
185
|
-
|
|
191
|
+
Options:
|
|
186
192
|
[--force] # Force to do some fooing
|
|
187
193
|
|
|
188
194
|
do some fooing
|
|
@@ -193,25 +199,18 @@ END
|
|
|
193
199
|
|
|
194
200
|
it "raises an error if the task can't be found" do
|
|
195
201
|
lambda {
|
|
196
|
-
MyScript.
|
|
202
|
+
MyScript.task_help(shell, "unknown")
|
|
197
203
|
}.must raise_error(Thor::Error, "task 'unknown' could not be found in namespace 'my_script'")
|
|
198
204
|
end
|
|
199
205
|
end
|
|
200
206
|
|
|
201
|
-
describe "
|
|
202
|
-
it "
|
|
203
|
-
capture(:stdout){ MyScript.help
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
it "does not show superclass tasks if required" do
|
|
207
|
-
capture(:stdout){ MyScript.help(shell, nil, :short => true) }.must_not =~ /help/
|
|
207
|
+
describe "instance method" do
|
|
208
|
+
it "calls the class method" do
|
|
209
|
+
capture(:stdout){ MyScript.start(["help"]) }.must =~ /Tasks:/
|
|
208
210
|
end
|
|
209
|
-
end
|
|
210
211
|
|
|
211
|
-
describe "instance method" do
|
|
212
212
|
it "calls the class method" do
|
|
213
|
-
|
|
214
|
-
MyScript.start(["help"])
|
|
213
|
+
capture(:stdout){ MyScript.start(["help", "foo"]) }.must =~ /Usage:/
|
|
215
214
|
end
|
|
216
215
|
end
|
|
217
216
|
end
|
data/spec/util_spec.rb
CHANGED
|
@@ -129,7 +129,7 @@ describe Thor::Util do
|
|
|
129
129
|
|
|
130
130
|
describe "#user_home" do
|
|
131
131
|
before(:each) do
|
|
132
|
-
stub(
|
|
132
|
+
ENV.stub!(:[])
|
|
133
133
|
Thor::Util.clear_user_home!
|
|
134
134
|
end
|
|
135
135
|
|
|
@@ -138,7 +138,7 @@ describe Thor::Util do
|
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
it "returns the *unix system path if file cannot be expanded and separator does not exist" do
|
|
141
|
-
|
|
141
|
+
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
|
142
142
|
previous_value = File::ALT_SEPARATOR
|
|
143
143
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
|
|
144
144
|
Thor::Util.user_home.must == "/"
|
|
@@ -146,7 +146,7 @@ describe Thor::Util do
|
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
it "returns the windows system path if file cannot be expanded and a separator exists" do
|
|
149
|
-
|
|
149
|
+
File.should_receive(:expand_path).with("~").and_raise(RuntimeError)
|
|
150
150
|
previous_value = File::ALT_SEPARATOR
|
|
151
151
|
capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
|
|
152
152
|
Thor::Util.user_home.must == "C:/"
|
|
@@ -154,43 +154,19 @@ describe Thor::Util do
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
it "returns HOME/.thor if set" do
|
|
157
|
-
stub(
|
|
157
|
+
ENV.stub!(:[]).with("HOME").and_return("/home/user/")
|
|
158
158
|
Thor::Util.user_home.must == "/home/user/"
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "returns path with HOMEDRIVE and HOMEPATH if set" do
|
|
162
|
-
stub(
|
|
163
|
-
stub(
|
|
162
|
+
ENV.stub!(:[]).with("HOMEDRIVE").and_return("D:/")
|
|
163
|
+
ENV.stub!(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
|
|
164
164
|
Thor::Util.user_home.must == "D:/Documents and Settings/James"
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
it "returns APPDATA/.thor if set" do
|
|
168
|
-
stub(
|
|
168
|
+
ENV.stub!(:[]).with("APPDATA").and_return("/home/user/")
|
|
169
169
|
Thor::Util.user_home.must == "/home/user/"
|
|
170
170
|
end
|
|
171
171
|
end
|
|
172
|
-
|
|
173
|
-
describe "#convert_constants_to_namespaces" do
|
|
174
|
-
before(:each) do
|
|
175
|
-
@hash = {
|
|
176
|
-
:git => {
|
|
177
|
-
:constants => [Object, "Thor::Sandbox::Package", Thor::CoreExt::OrderedHash]
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "converts constants in the hash to namespaces" do
|
|
183
|
-
Thor::Util.convert_constants_to_namespaces(@hash)
|
|
184
|
-
@hash[:git][:namespaces].must == [ "object", "package", "thor:core_ext:ordered_hash" ]
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it "returns true if the hash changed" do
|
|
188
|
-
Thor::Util.convert_constants_to_namespaces(@hash).must be_true
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it "does not add namespaces to the hash if namespaces were already added" do
|
|
192
|
-
Thor::Util.convert_constants_to_namespaces(@hash)
|
|
193
|
-
Thor::Util.convert_constants_to_namespaces(@hash).must be_false
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
172
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yehuda Katz
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date:
|
|
13
|
+
date: 2010-01-18 00:00:00 +01:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies: []
|
|
16
16
|
|
|
@@ -41,6 +41,7 @@ files:
|
|
|
41
41
|
- lib/thor/actions/file_manipulation.rb
|
|
42
42
|
- lib/thor/actions/inject_into_file.rb
|
|
43
43
|
- lib/thor/base.rb
|
|
44
|
+
- lib/thor/core_ext/file_binary_read.rb
|
|
44
45
|
- lib/thor/core_ext/hash_with_indifferent_access.rb
|
|
45
46
|
- lib/thor/core_ext/ordered_hash.rb
|
|
46
47
|
- lib/thor/error.rb
|
|
@@ -88,30 +89,38 @@ signing_key:
|
|
|
88
89
|
specification_version: 3
|
|
89
90
|
summary: A scripting framework that replaces rake, sake and rubigen
|
|
90
91
|
test_files:
|
|
91
|
-
- spec/
|
|
92
|
+
- spec/actions/create_file_spec.rb
|
|
92
93
|
- spec/actions/directory_spec.rb
|
|
93
94
|
- spec/actions/empty_directory_spec.rb
|
|
94
|
-
- spec/actions/create_file_spec.rb
|
|
95
|
-
- spec/actions/inject_into_file_spec.rb
|
|
96
95
|
- spec/actions/file_manipulation_spec.rb
|
|
97
|
-
- spec/
|
|
98
|
-
- spec/invocation_spec.rb
|
|
99
|
-
- spec/base_spec.rb
|
|
100
|
-
- spec/task_spec.rb
|
|
101
|
-
- spec/spec_helper.rb
|
|
96
|
+
- spec/actions/inject_into_file_spec.rb
|
|
102
97
|
- spec/actions_spec.rb
|
|
103
|
-
- spec/
|
|
104
|
-
- spec/
|
|
105
|
-
- spec/
|
|
106
|
-
- spec/thor_spec.rb
|
|
98
|
+
- spec/base_spec.rb
|
|
99
|
+
- spec/core_ext/hash_with_indifferent_access_spec.rb
|
|
100
|
+
- spec/core_ext/ordered_hash_spec.rb
|
|
107
101
|
- spec/fixtures/application.rb
|
|
108
|
-
- spec/fixtures/doc/config.rb
|
|
109
102
|
- spec/fixtures/bundle/execute.rb
|
|
110
|
-
- spec/
|
|
103
|
+
- spec/fixtures/doc/config.rb
|
|
104
|
+
- spec/group_spec.rb
|
|
105
|
+
- spec/invocation_spec.rb
|
|
111
106
|
- spec/parser/argument_spec.rb
|
|
107
|
+
- spec/parser/arguments_spec.rb
|
|
112
108
|
- spec/parser/option_spec.rb
|
|
113
109
|
- spec/parser/options_spec.rb
|
|
114
|
-
- spec/
|
|
110
|
+
- spec/rake_compat_spec.rb
|
|
115
111
|
- spec/runner_spec.rb
|
|
116
|
-
- spec/
|
|
117
|
-
- spec/
|
|
112
|
+
- spec/shell/basic_spec.rb
|
|
113
|
+
- spec/shell/color_spec.rb
|
|
114
|
+
- spec/shell_spec.rb
|
|
115
|
+
- spec/spec_helper.rb
|
|
116
|
+
- spec/task_spec.rb
|
|
117
|
+
- spec/thor_spec.rb
|
|
118
|
+
- spec/util_spec.rb
|
|
119
|
+
- spec/fixtures/bundle/main.thor
|
|
120
|
+
- spec/fixtures/doc/%file_name%.rb.tt
|
|
121
|
+
- spec/fixtures/doc/README
|
|
122
|
+
- spec/fixtures/group.thor
|
|
123
|
+
- spec/fixtures/invoke.thor
|
|
124
|
+
- spec/fixtures/script.thor
|
|
125
|
+
- spec/fixtures/task.thor
|
|
126
|
+
- spec/spec.opts
|