|
3 | 3 | require "spec_helper"
|
4 | 4 |
|
5 | 5 | describe GitCommander::Command do
|
| 6 | + let(:output) { spy("output") } |
| 7 | + |
6 | 8 | it "runs the block registered to it" do
|
7 |
| - output = spy("output") |
8 | 9 | command = described_class.new(:wtf, output: output) do
|
9 | 10 | say "I'm on a boat!"
|
10 | 11 | end
|
|
13 | 14 | end
|
14 | 15 |
|
15 | 16 | it "runs the block registered to it passing arguments" do
|
16 |
| - output = spy("output") |
17 |
| - command = described_class.new(:wtf, output: output) do |vehicle:| |
| 17 | + command = described_class.new(:wtf, output: output, arguments: [{ name: :vehicle }]) do |vehicle:| |
18 | 18 | say "I'm on a #{vehicle}!"
|
19 | 19 | end
|
20 |
| - command.run vehicle: "T-Rex" |
| 20 | + command.run [GitCommander::Command::Option.new(name: :vehicle, value: "T-Rex")] |
21 | 21 | expect(output).to have_received(:puts).with "I'm on a T-Rex!"
|
22 | 22 | end
|
23 |
| - it "runs the block registered to it passing options" |
| 23 | + |
| 24 | + it "runs the block registered to it passing options" do |
| 25 | + command = described_class.new( |
| 26 | + :wtf, |
| 27 | + output: output, |
| 28 | + flags: [{ name: :make, default: "Lotus" }], |
| 29 | + switches: [{ name: :model }] |
| 30 | + ) do |params| |
| 31 | + say "I'm on a #{[params[:make], params[:model]].compact.join(" ")}!" |
| 32 | + end |
| 33 | + command.run [GitCommander::Command::Option.new(name: :model, value: "Evora")] |
| 34 | + expect(output).to have_received(:puts).with "I'm on a Lotus Evora!" |
| 35 | + end |
| 36 | + |
24 | 37 | it "runs the block registered to it passing arguments and options"
|
25 | 38 | it "runs the block registered to it passing options with defaults"
|
26 | 39 |
|
27 | 40 | it "can add output" do
|
28 |
| - output = spy("output") |
29 | 41 | command = described_class.new(:wtf, output: output)
|
30 | 42 | command.say "Ooh eeh what's up with that"
|
31 | 43 | expect(output).to have_received(:puts).with "Ooh eeh what's up with that"
|
|
34 | 46 | it "raises an error if no arguments, flags, or switches exist for the params passed"
|
35 | 47 |
|
36 | 48 | it "can output a help message" do
|
37 |
| - output = spy("output") |
38 | 49 | full_command = described_class.new(
|
39 | 50 | :start,
|
40 | 51 | arguments: [
|
|
0 commit comments