File: sort_spec.rb

package info (click to toggle)
ruby-thor 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 904 kB
  • sloc: ruby: 9,250; makefile: 8; sh: 1
file content (75 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (2)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require "helper"

describe Thor do
  def shell
    @shell ||= Thor::Base.shell.new
  end

  describe "#sort - default" do
    my_script = Class.new(Thor) do
      desc "a", "First Command"
      def a; end

      desc "z", "Last Command"
      def z; end
    end

    before do
      @content = capture(:stdout) { my_script.help(shell) }
    end

    it "sorts them lexicographillay" do
      expect(@content).to match(/:a.+:help.+:z/m)
    end
  end


  describe "#sort - simple override" do
    my_script = Class.new(Thor) do
      desc "a", "First Command"
      def a; end

      desc "z", "Last Command"
      def z; end

      def self.sort_commands!(list)
        list.sort!
        list.reverse!
      end

    end

    before do
      @content = capture(:stdout) { my_script.help(shell) }
    end

    it "sorts them in reverse" do
      expect(@content).to match(/:z.+:help.+:a/m)
    end
  end


  describe "#sort - simple override" do
    my_script = Class.new(Thor) do
      desc "a", "First Command"
      def a; end

      desc "z", "Last Command"
      def z; end

      def self.sort_commands!(list)
        list.sort_by! do |a,b|
          a[0] == :help ? -1 : a[0] <=> b[0]
        end
      end
    end

    before do
      @content = capture(:stdout) { my_script.help(shell) }
    end

    it "puts help first then sorts them lexicographillay" do
      expect(@content).to match(/:help.+:a.+:z/m)
    end
  end
end