@@ -82,6 +82,20 @@ def say
82
82
default_command :say
83
83
end
84
84
85
+ class SubcommandWithDefault < Thor
86
+ default_command :default
87
+
88
+ desc 'default' , 'default subcommand'
89
+ def default
90
+ puts 'default'
91
+ end
92
+
93
+ desc 'with_args' , 'subcommand with arguments'
94
+ def with_args ( *args )
95
+ puts 'received arguments: ' + args . join ( ',' )
96
+ end
97
+ end
98
+
85
99
BoringVendorProvidedCLI . register (
86
100
ExcitingPluginCLI ,
87
101
'exciting' ,
@@ -125,6 +139,9 @@ def say
125
139
'say message' ,
126
140
'subcommands ftw' )
127
141
142
+ BoringVendorProvidedCLI . register ( SubcommandWithDefault ,
143
+ 'subcommand' , 'subcommand' , 'Run subcommands' )
144
+
128
145
describe '.register-ing a Thor subclass' do
129
146
it 'registers the plugin as a subcommand' do
130
147
fireworks_output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ exciting fireworks ] ) }
@@ -136,20 +153,33 @@ def say
136
153
expect ( help_output ) . to include ( 'do exciting things' )
137
154
end
138
155
139
- it 'invokes the default command correctly' do
140
- output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ say hello ] ) }
141
- expect ( output ) . to include ( 'hello' )
142
- end
156
+ context 'with a default command,' do
157
+ it 'invokes the default command correctly' do
158
+ output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ say hello ] ) }
159
+ expect ( output ) . to include ( 'hello' )
160
+ end
143
161
144
- it 'invokes the default command 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
162
+ it 'invokes the default command correctly with multiple args' do
163
+ output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ say_multiple hello adam ] ) }
164
+ expect ( output ) . to include ( 'hello' )
165
+ expect ( output ) . to include ( 'adam' )
166
+ end
167
+
168
+ it 'invokes the default command correctly with a declared argument' do
169
+ output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ say_argument hello ] ) }
170
+ expect ( output ) . to include ( 'hello' )
171
+ end
172
+
173
+ it "displays the subcommand's help message" do
174
+ output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ subcommand help ] ) }
175
+ expect ( output ) . to include ( 'default subcommand' )
176
+ expect ( output ) . to include ( 'subcommand with argument' )
177
+ end
149
178
150
- it 'invokes the default command correctly with a declared argument' do
151
- output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ say_argument hello ] ) }
152
- expect ( output ) . to include ( 'hello' )
179
+ it "invokes commands with their actual args" do
180
+ output = capture ( :stdout ) { BoringVendorProvidedCLI . start ( %w[ subcommand with_args actual_argument ] ) }
181
+ expect ( output . strip ) . to eql ( 'received arguments: actual_argument' )
182
+ end
153
183
end
154
184
155
185
context 'when $thor_runner is false' do
0 commit comments