thor 0.12.0 → 0.12.2

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.
@@ -0,0 +1,10 @@
1
+ # module: random
2
+
3
+ class Amazing < Thor
4
+ desc "describe NAME", "say that someone is amazing"
5
+ method_options :forcefully => :boolean
6
+ def describe(name, opts)
7
+ ret = "#{name} is amazing"
8
+ puts opts["forcefully"] ? ret.upcase : ret
9
+ end
10
+ end
@@ -78,12 +78,12 @@ describe Thor::Runner do
78
78
  lambda { Thor::Runner.start }.must raise_error(NoMethodError)
79
79
  end
80
80
 
81
- it "does not swallow Thor::Group ArgumentError" do
81
+ it "does not swallow Thor::Group InvocationError" do
82
82
  ARGV.replace ["whiny_generator"]
83
83
  lambda { Thor::Runner.start }.must raise_error(ArgumentError, /Are you sure it has arity equals to 0\?/)
84
84
  end
85
85
 
86
- it "does not swallow Thor ArgumentError" do
86
+ it "does not swallow Thor InvocationError" do
87
87
  ARGV.replace ["my_script:animal"]
88
88
  capture(:stderr) { Thor::Runner.start }.must =~ /'animal' was called incorrectly\. Call as 'my_script:animal TYPE'/
89
89
  end
@@ -110,7 +110,7 @@ describe Thor::Runner do
110
110
  it "gives a list of the available tasks" do
111
111
  ARGV.replace ["list"]
112
112
  content = capture(:stdout) { Thor::Runner.start }
113
- content.must =~ /amazing:describe NAME \[\-\-forcefully\]\s+# say that someone is amazing/m
113
+ content.must =~ /amazing:describe NAME\s+# say that someone is amazing/m
114
114
  end
115
115
 
116
116
  it "gives a list of the available Thor::Group classes" do
@@ -141,7 +141,7 @@ describe Thor::Runner do
141
141
 
142
142
  it "presents tasks in the default namespace with an empty namespace" do
143
143
  ARGV.replace ["list"]
144
- capture(:stdout) { Thor::Runner.start }.must =~ /^:test\s+# prints 'test'/m
144
+ capture(:stdout) { Thor::Runner.start }.must =~ /^thor :test\s+# prints 'test'/m
145
145
  end
146
146
 
147
147
  it "runs tasks with an empty namespace from the default namespace" do
@@ -183,7 +183,7 @@ describe Thor::Runner do
183
183
  it "displays the modules installed in a pretty way" do
184
184
  stdout = capture(:stdout) { Thor::Runner.start(["installed"]) }
185
185
  stdout.must =~ /random\s*amazing/
186
- stdout.must =~ /amazing:describe NAME \[\-\-forcefully\]\s+# say that someone is amazing/m
186
+ stdout.must =~ /amazing:describe NAME\s+# say that someone is amazing/m
187
187
  end
188
188
  end
189
189
 
@@ -96,28 +96,6 @@ describe Thor::Shell::Basic do
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,6 +119,16 @@ 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
+ mock(shell).terminal_width { 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
@@ -152,6 +140,12 @@ TABLE
152
140
  shell.file_collision('foo')
153
141
  end
154
142
 
143
+ it "returns true if the user choose default option" do
144
+ stub($stdout).print
145
+ mock($stdin).gets{ '' }
146
+ shell.file_collision('foo').must be_true
147
+ end
148
+
155
149
  it "returns false if the user choose no" do
156
150
  stub($stdout).print
157
151
  mock($stdin).gets{ 'n' }
@@ -0,0 +1 @@
1
+ --color
@@ -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
14
  stub(Object).namespace{ "foo" }
19
15
  stub(Object).arguments{ [] }
20
- task(:bar => :required).formatted_usage(Object, true).must == "foo:can_has --bar=BAR"
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"
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
20
  stub(Object).namespace{ "default:foo" }
31
21
  stub(Object).arguments{ [] }
32
- task(:bar => :required).formatted_usage(Object, true).must == ":foo:can_has --bar=BAR"
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
26
  stub(Object).namespace{ "foo" }
37
27
  stub(Object).arguments{ [ Thor::Argument.new(:bar, nil, true, :string) ] }
38
- task(:foo => true).formatted_usage(Object).must == "can_has BAR [--foo]"
28
+ task(:foo => :required).formatted_usage(Object).must == "foo:can_has BAR --foo=FOO"
39
29
  end
40
30
  end
41
31
 
@@ -75,14 +65,4 @@ describe Thor::Task do
75
65
  }.must raise_error(Thor::UndefinedTaskError, "the 'can_has' task of Object is private")
76
66
  end
77
67
  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"
86
- end
87
- end
88
68
  end
@@ -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 \[\-\-other=OTHER\]\s+# fish around/m
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/m
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/m
155
+ @content.must =~ /animal TYPE\s+# horse around/
156
+ end
157
+
158
+ it "uses the maximum terminal size to show tasks" do
159
+ mock(@shell).terminal_width { 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/m
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 \[\-\-force\]\s+# do some fooing/m
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 =~ /Class options\:/
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.help(shell, "foo") }.must == <<END
187
+ capture(:stdout) { MyScript.help(shell, :task => "foo") }.must == <<END
182
188
  Usage:
183
- foo BAR
189
+ thor my_script:foo BAR
184
190
 
185
- Method options:
191
+ Options:
186
192
  [--force] # Force to do some fooing
187
193
 
188
194
  do some fooing
@@ -193,24 +199,20 @@ END
193
199
 
194
200
  it "raises an error if the task can't be found" do
195
201
  lambda {
196
- MyScript.help(shell, "unknown")
202
+ MyScript.help(shell, :task => "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
207
  describe "options" do
202
- it "shows the namespace if required" do
203
- capture(:stdout){ MyScript.help(shell, nil, :namespace => true) }.must =~ /my_script:foo BAR/
204
- end
205
-
206
208
  it "does not show superclass tasks if required" do
207
- capture(:stdout){ MyScript.help(shell, nil, :short => true) }.must_not =~ /help/
209
+ capture(:stdout){ MyScript.help(shell, :short => true) }.must_not =~ /help/
208
210
  end
209
211
  end
210
212
 
211
213
  describe "instance method" do
212
214
  it "calls the class method" do
213
- stub(MyScript).help(mock.instance_of(Thor::Base.shell), nil, :namespace => nil)
215
+ stub(MyScript).help(mock.instance_of(Thor::Base.shell), :task => nil)
214
216
  MyScript.start(["help"])
215
217
  end
216
218
  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.0
4
+ version: 0.12.2
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: 2009-11-09 00:00:00 -02:00
13
+ date: 2010-01-01 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -88,30 +88,65 @@ signing_key:
88
88
  specification_version: 3
89
89
  summary: A scripting framework that replaces rake, sake and rubigen
90
90
  test_files:
91
- - spec/rake_compat_spec.rb
91
+ - spec/actions/create_file_spec.rb
92
92
  - spec/actions/directory_spec.rb
93
93
  - spec/actions/empty_directory_spec.rb
94
- - spec/actions/create_file_spec.rb
95
- - spec/actions/inject_into_file_spec.rb
96
94
  - spec/actions/file_manipulation_spec.rb
97
- - spec/shell_spec.rb
98
- - spec/invocation_spec.rb
99
- - spec/base_spec.rb
100
- - spec/task_spec.rb
101
- - spec/spec_helper.rb
95
+ - spec/actions/inject_into_file_spec.rb
102
96
  - spec/actions_spec.rb
97
+ - spec/base_spec.rb
98
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
99
+ - spec/core_ext/ordered_hash_spec.rb
100
+ - spec/fixtures/application.rb
101
+ - spec/fixtures/bundle/execute.rb
102
+ - spec/fixtures/doc/config.rb
103
+ - spec/group_spec.rb
104
+ - spec/invocation_spec.rb
105
+ - spec/parser/argument_spec.rb
106
+ - spec/parser/arguments_spec.rb
107
+ - spec/parser/option_spec.rb
108
+ - spec/parser/options_spec.rb
109
+ - spec/rake_compat_spec.rb
110
+ - spec/runner_spec.rb
103
111
  - spec/shell/basic_spec.rb
104
112
  - spec/shell/color_spec.rb
105
- - spec/group_spec.rb
113
+ - spec/shell_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/task_spec.rb
106
116
  - spec/thor_spec.rb
117
+ - spec/util_spec.rb
118
+ - spec/actions/create_file_spec.rb
119
+ - spec/actions/directory_spec.rb
120
+ - spec/actions/empty_directory_spec.rb
121
+ - spec/actions/file_manipulation_spec.rb
122
+ - spec/actions/inject_into_file_spec.rb
123
+ - spec/actions_spec.rb
124
+ - spec/base_spec.rb
125
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
126
+ - spec/core_ext/ordered_hash_spec.rb
107
127
  - spec/fixtures/application.rb
108
- - spec/fixtures/doc/config.rb
109
128
  - spec/fixtures/bundle/execute.rb
110
- - spec/util_spec.rb
129
+ - spec/fixtures/bundle/main.thor
130
+ - spec/fixtures/doc/%file_name%.rb.tt
131
+ - spec/fixtures/doc/config.rb
132
+ - spec/fixtures/doc/README
133
+ - spec/fixtures/group.thor
134
+ - spec/fixtures/invoke.thor
135
+ - spec/fixtures/script.thor
136
+ - spec/fixtures/task.thor
137
+ - spec/group_spec.rb
138
+ - spec/invocation_spec.rb
111
139
  - spec/parser/argument_spec.rb
140
+ - spec/parser/arguments_spec.rb
112
141
  - spec/parser/option_spec.rb
113
142
  - spec/parser/options_spec.rb
114
- - spec/parser/arguments_spec.rb
143
+ - spec/rake_compat_spec.rb
115
144
  - spec/runner_spec.rb
116
- - spec/core_ext/ordered_hash_spec.rb
117
- - spec/core_ext/hash_with_indifferent_access_spec.rb
145
+ - spec/shell/basic_spec.rb
146
+ - spec/shell/color_spec.rb
147
+ - spec/shell_spec.rb
148
+ - spec/spec.opts
149
+ - spec/spec_helper.rb
150
+ - spec/task_spec.rb
151
+ - spec/thor_spec.rb
152
+ - spec/util_spec.rb