1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe YARD::CLI::CommandParser do
describe "#run" do
before do
@cmd = CLI::CommandParser.new
end
it "shows help if --help is provided" do
command = double(:command)
expect(command).to receive(:run).with('--help')
CLI::CommandParser.commands[:foo] = command
@cmd.class.default_command = :foo
@cmd.run(*%w(foo --help))
end
it "uses default command if first argument is a switch" do
command = double(:command)
expect(command).to receive(:run).with('--a', 'b', 'c')
CLI::CommandParser.commands[:foo] = command
@cmd.class.default_command = :foo
@cmd.run(*%w(--a b c))
end
it "uses default command if no arguments are provided" do
command = double(:command)
expect(command).to receive(:run)
CLI::CommandParser.commands[:foo] = command
@cmd.class.default_command = :foo
@cmd.run
end
it "lists commands if command is not found" do
expect(@cmd).to receive(:list_commands)
@cmd.run(*%w(unknown_command --args))
end
it "lists commands if --help is provided as sole argument" do
expect(@cmd).to receive(:list_commands)
@cmd.run(*%w(--help))
end
end
end
|