File: tree_spec.rb

package info (click to toggle)
ruby-thor 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 924 kB
  • sloc: ruby: 9,491; makefile: 8; sh: 1
file content (49 lines) | stat: -rw-r--r-- 1,401 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
require "helper"
require "thor"

class TreeApp < Thor
  desc "command1", "A top level command"

  def command1
  end

  desc "command2", "Another top level command"

  def command2
  end

  class SubApp < Thor
    desc "subcommand1", "A subcommand"

    def subcommand1
    end
  end

  desc "sub", "Subcommands"
  subcommand "sub", SubApp
end

RSpec.describe "Thor tree command" do
  let(:shell) { Thor::Shell::Basic.new }

  it "prints a tree of all commands" do
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/├─ command1/)
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/├─ command2/)
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/└─ sub/)
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/subcommand1/)
  end

  it "includes command descriptions" do
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/A top level command/)
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/Another top level command/)
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).to match(/A subcommand/)
  end

  it "doesn't show hidden commands" do
    expect(capture(:stdout) { TreeApp.start(["tree"]) }).not_to match(/help/)
  end

  it "shows tree command in help" do
    expect(capture(:stdout) { TreeApp.start(["help"]) }).to match(/tree.*Print a tree of all available commands/)
  end
end