File: command_option_reordering_spec.rb

package info (click to toggle)
ruby-clamp 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: ruby: 2,851; makefile: 4
file content (58 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require "spec_helper"

describe Clamp::Command do

  extend CommandFactory
  include OutputCapture

  context "with allow_options_after_parameters enabled" do

    before do
      Clamp.allow_options_after_parameters = true
    end

    after do
      Clamp.allow_options_after_parameters = false
    end

    given_command("cmd") do

      option ["-v", "--verbose"], :flag, "Be noisy"

      subcommand "say", "Say something" do

        option "--loud", :flag, "say it loud"

        parameter "WORDS ...", "the thing to say", attribute_name: :words

        def execute
          message = words.join(" ")
          message = message.upcase if loud?
          message *= 3 if verbose?
          $stdout.puts message
        end

      end

    end

    it "still works" do
      command.run(%w[say foo])
      expect(stdout).to eq "foo\n"
    end

    it "honours options after positional arguments" do
      command.run(%w[say blah --verbose])
      expect(stdout).to eq "blahblahblah\n"
    end

    it "honours options declared on subcommands" do
      command.run(%w[say --loud blah])
      expect(stdout).to eq "BLAH\n"
    end

  end

end