|
140 | 140 | it "returns a Command object of the first default command" do |
141 | 141 | expect(subject.default_command).to be_a Script::Command |
142 | 142 | expect(subject.default_command.name).to eq 'get' |
143 | | - end |
| 143 | + end |
144 | 144 | end |
145 | 145 |
|
146 | 146 | describe '#default_flags' do |
|
238 | 238 | end |
239 | 239 | end |
240 | 240 |
|
| 241 | + describe '#global_flags?' do |
| 242 | + context "when a command has flags and commands" do |
| 243 | + let(:fixture) { :mode_global_flags } |
| 244 | + |
| 245 | + it "returns true" do |
| 246 | + expect(subject.global_flags?).to be_truthy |
| 247 | + end |
| 248 | + end |
| 249 | + |
| 250 | + context "when a command has flags but no commands" do |
| 251 | + let(:fixture) { :mode_flags } |
| 252 | + |
| 253 | + it "returns false" do |
| 254 | + expect(subject.global_flags?).to be_falsy |
| 255 | + end |
| 256 | + end |
| 257 | + |
| 258 | + context "when a command has commands but no flags" do |
| 259 | + let(:fixture) { :mode_commands } |
| 260 | + |
| 261 | + it "returns false" do |
| 262 | + expect(subject.global_flags?).to be_falsy |
| 263 | + end |
| 264 | + end |
| 265 | + end |
| 266 | + |
241 | 267 | describe '#group_string' do |
242 | 268 | it "returns a string suitable for showing the group in usage" do |
243 | 269 | expect(subject.group_string).to eq "Commands:" |
|
352 | 378 | end |
353 | 379 | end |
354 | 380 |
|
| 381 | + describe '#mode' do |
| 382 | + context "when flags and commands are defined" do |
| 383 | + let(:fixture) { :mode_global_flags } |
| 384 | + |
| 385 | + it "returns :global_flags" do |
| 386 | + expect(subject.mode).to eq :global_flags |
| 387 | + end |
| 388 | + end |
| 389 | + |
| 390 | + context "when only commands are defined" do |
| 391 | + let(:fixture) { :mode_commands } |
| 392 | + |
| 393 | + it "returns :commands" do |
| 394 | + expect(subject.mode).to eq :commands |
| 395 | + end |
| 396 | + end |
| 397 | + |
| 398 | + context "when args and flags are defined" do |
| 399 | + let(:fixture) { :mode_args_and_flags } |
| 400 | + |
| 401 | + it "returns :args_and_flags" do |
| 402 | + expect(subject.mode).to eq :args_and_flags |
| 403 | + end |
| 404 | + end |
| 405 | + |
| 406 | + context "when only args are defined" do |
| 407 | + let(:fixture) { :mode_args } |
| 408 | + |
| 409 | + it "returns :args" do |
| 410 | + expect(subject.mode).to eq :args |
| 411 | + end |
| 412 | + end |
| 413 | + |
| 414 | + context "when only flags are defined" do |
| 415 | + let(:fixture) { :mode_flags } |
| 416 | + |
| 417 | + it "returns :flags" do |
| 418 | + expect(subject.mode).to eq :flags |
| 419 | + end |
| 420 | + end |
| 421 | + |
| 422 | + context "when nothing is defined" do |
| 423 | + let(:fixture) { :mode_empty } |
| 424 | + |
| 425 | + it "returns :empty" do |
| 426 | + expect(subject.mode).to eq :empty |
| 427 | + end |
| 428 | + end |
| 429 | + end |
| 430 | + |
355 | 431 | describe '#usage_string' do |
356 | | - context "when no args and no commands are defined" do |
357 | | - let(:fixture) { :git_status } |
| 432 | + context "when flags and commands are defined" do |
| 433 | + let(:fixture) { :mode_global_flags } |
358 | 434 |
|
359 | | - it "returns a string suitable to be used as a usage pattern" do |
360 | | - expect(subject.usage_string).to eq "git status" |
| 435 | + it "returns the correct string" do |
| 436 | + expect(subject.usage_string).to eq "get [OPTIONS] COMMAND" |
361 | 437 | end |
362 | 438 | end |
363 | 439 |
|
364 | | - context "when flags are defined" do |
365 | | - let(:fixture) { :flags_only_command } |
| 440 | + context "when only commands are defined" do |
| 441 | + let(:fixture) { :mode_commands } |
366 | 442 |
|
367 | | - it "adds [OPTIONS] to the usage string" do |
368 | | - expect(subject.usage_string).to eq "git status [OPTIONS]" |
369 | | - end |
| 443 | + it "returns the correct string" do |
| 444 | + expect(subject.usage_string).to eq "get COMMAND" |
| 445 | + end |
370 | 446 | end |
371 | 447 |
|
372 | | - context "when args are defined" do |
373 | | - it "includes them in the usage string" do |
374 | | - expect(subject.usage_string).to eq "get SOURCE [TARGET] [OPTIONS]" |
375 | | - end |
| 448 | + context "when args and flags are defined" do |
| 449 | + let(:fixture) { :mode_args_and_flags } |
| 450 | + |
| 451 | + it "returns the correct string" do |
| 452 | + expect(subject.usage_string).to eq "get SOURCE [TARGET] [OPTIONS] [PARAMS...]" |
| 453 | + end |
| 454 | + end |
| 455 | + |
| 456 | + context "when only args are defined" do |
| 457 | + let(:fixture) { :mode_args } |
| 458 | + |
| 459 | + it "returns the correct string" do |
| 460 | + expect(subject.usage_string).to eq "get SOURCE [TARGET] [PARAMS...]" |
| 461 | + end |
376 | 462 | end |
377 | 463 |
|
378 | | - context "when commands are defined" do |
379 | | - let(:fixture) { :docker } |
| 464 | + context "when only flags are defined" do |
| 465 | + let(:fixture) { :mode_flags } |
380 | 466 |
|
381 | | - it "includes [command] in the usage string" do |
382 | | - expect(subject.usage_string).to eq "docker COMMAND" |
383 | | - end |
| 467 | + it "returns the correct string" do |
| 468 | + expect(subject.usage_string).to eq "get [OPTIONS] [PARAMS...]" |
| 469 | + end |
| 470 | + |
| 471 | + context "when it has a parent" do |
| 472 | + let(:fixture) { :flags_only_command } |
| 473 | + |
| 474 | + it "returns the correct string" do |
| 475 | + expect(subject.usage_string).to eq "git status [OPTIONS]" |
| 476 | + end |
| 477 | + end |
384 | 478 | end |
385 | 479 |
|
386 | | - context "when catch_all is enabled" do |
387 | | - let(:fixture) { :catch_all } |
| 480 | + context "when nothing is defined" do |
| 481 | + let(:fixture) { :mode_empty } |
| 482 | + |
| 483 | + it "returns the correct string" do |
| 484 | + expect(subject.usage_string).to eq "get [PARAMS...]" |
| 485 | + end |
| 486 | + |
| 487 | + context "when it has a parent" do |
| 488 | + let(:fixture) { :git_status } |
388 | 489 |
|
389 | | - it "includes the catch_all usage string" do |
390 | | - expect(subject.usage_string).to eq "get [...]" |
| 490 | + it "returns the correct string" do |
| 491 | + expect(subject.usage_string).to eq "git status" |
| 492 | + end |
391 | 493 | end |
392 | 494 | end |
393 | 495 | end |
|
0 commit comments