|
9 | 9 | it "shows usage" do |
10 | 10 | _, stderr, = Open3.capture3("baz") |
11 | 11 | expect(stderr).to eq( |
12 | | - "ERROR: \"#{cmd}\" was called with no arguments\nUsage: \"#{cmd} MANDATORY_ARG\"\n" |
| 12 | + "ERROR: \"#{cmd}\" was called with no arguments\n"\ |
| 13 | + "Usage: \"#{cmd} MANDATORY_ARG --mandatory-option=VALUE --mandatory-option-with-default=VALUE\"\n" |
13 | 14 | ) |
14 | 15 | end |
15 | 16 |
|
|
33 | 34 | --option-one=VALUE, -1 VALUE # Option one |
34 | 35 | --[no-]boolean-option, -b # Option boolean |
35 | 36 | --option-with-default=VALUE, -d VALUE # Option default, default: "test" |
| 37 | + --mandatory-option=VALUE # REQUIRED Mandatory option |
| 38 | + --mandatory-option-with-default=VALUE # REQUIRED Mandatory option, default: "mandatory default" |
36 | 39 | --help, -h # Print this help |
37 | 40 | OUTPUT |
38 | 41 | expect(output).to eq(expected_output) |
39 | 42 | end |
40 | 43 |
|
41 | | - it "with option_one" do |
42 | | - output = `baz first_arg --option-one=test2` |
43 | | - expect(output).to eq( |
44 | | - "mandatory_arg: first_arg. optional_arg: optional_arg. " \ |
45 | | - "Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n" |
46 | | - ) |
| 44 | + context "with mandatory arg and non-required option" do |
| 45 | + it "errors out and shows usage" do |
| 46 | + _, stderr, = Open3.capture3("baz first_arg --option_one=test2") |
| 47 | + expect(stderr).to eq( |
| 48 | + "ERROR: \"#{cmd}\" was called with arguments [\"first_arg\"] and options {:option_one=>\"test2\"}\n" \ |
| 49 | + "Usage: \"#{cmd} MANDATORY_ARG --mandatory-option=VALUE --mandatory-option-with-default=VALUE\"\n" |
| 50 | + ) |
| 51 | + end |
47 | 52 | end |
48 | 53 |
|
49 | | - it "with combination of aliases" do |
50 | | - output = `baz first_arg -bd test3` |
51 | | - expect(output).to eq( |
52 | | - "mandatory_arg: first_arg. optional_arg: optional_arg. " \ |
53 | | - "Options: {:option_with_default=>\"test3\", :boolean_option=>true}\n" |
54 | | - ) |
| 54 | + context "with mandatory arg and mandatory_option" do |
| 55 | + it "works" do |
| 56 | + output = `baz first_arg --mandatory-option=test1` |
| 57 | + expect(output).to eq( |
| 58 | + "mandatory_arg: first_arg. optional_arg: optional_arg. " \ |
| 59 | + "mandatory_option: test1. " \ |
| 60 | + "Options: {:option_with_default=>\"test\", " \ |
| 61 | + ":mandatory_option_with_default=>\"mandatory default\", " \ |
| 62 | + ":mandatory_option=>\"test1\"}\n" |
| 63 | + ) |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + context "with mandatory arg, option_one and mandatory_option" do |
| 68 | + it "works" do |
| 69 | + output = `baz first_arg --mandatory-option=test1 --option_one=test2` |
| 70 | + expect(output).to eq( |
| 71 | + "mandatory_arg: first_arg. optional_arg: optional_arg. " \ |
| 72 | + "mandatory_option: test1. " \ |
| 73 | + "Options: {:option_with_default=>\"test\", " \ |
| 74 | + ":mandatory_option_with_default=>\"mandatory default\", " \ |
| 75 | + ":mandatory_option=>\"test1\", :option_one=>\"test2\"}\n" |
| 76 | + ) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context "with combination of aliases" do |
| 81 | + it "works" do |
| 82 | + output = `baz first_arg --mandatory-option test1 -bd test3` |
| 83 | + expect(output).to eq( |
| 84 | + "mandatory_arg: first_arg. optional_arg: optional_arg. " \ |
| 85 | + "mandatory_option: test1. " \ |
| 86 | + "Options: {:option_with_default=>\"test3\", " \ |
| 87 | + ":mandatory_option_with_default=>\"mandatory default\", " \ |
| 88 | + ":mandatory_option=>\"test1\", :boolean_option=>true}\n" |
| 89 | + ) |
| 90 | + end |
55 | 91 | end |
56 | 92 | end |
57 | 93 |
|
58 | 94 | context "root command with arguments and subcommands" do |
59 | | - it "with arguments" do |
60 | | - output = `foo root-command "hello world"` |
| 95 | + context "with arguments" do |
| 96 | + it "works" do |
| 97 | + output = `foo root-command "hello world"` |
61 | 98 |
|
62 | | - expected = <<~DESC |
63 | | - I'm a root-command argument:hello world |
64 | | - I'm a root-command option: |
65 | | - DESC |
| 99 | + expected = <<~DESC |
| 100 | + I'm a root-command argument:hello world |
| 101 | + I'm a root-command option: |
| 102 | + DESC |
66 | 103 |
|
67 | | - expect(output).to eq(expected) |
| 104 | + expect(output).to eq(expected) |
| 105 | + end |
68 | 106 | end |
69 | 107 |
|
70 | | - it "with options" do |
71 | | - output = `foo root-command "hello world" --root-command-option="bye world"` |
| 108 | + context "with options" do |
| 109 | + it "works" do |
| 110 | + output = `foo root-command "hello world" --root-command-option="bye world"` |
72 | 111 |
|
73 | | - expected = <<~DESC |
74 | | - I'm a root-command argument:hello world |
75 | | - I'm a root-command option:bye world |
76 | | - DESC |
| 112 | + expected = <<~DESC |
| 113 | + I'm a root-command argument:hello world |
| 114 | + I'm a root-command option:bye world |
| 115 | + DESC |
77 | 116 |
|
78 | | - expect(output).to eq(expected) |
| 117 | + expect(output).to eq(expected) |
| 118 | + end |
79 | 119 | end |
80 | 120 | end |
81 | 121 | end |
0 commit comments