File: cli_spec.rb

package info (click to toggle)
ticgit 1.0.2.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: ruby: 2,848; sh: 124; makefile: 16
file content (220 lines) | stat: -rw-r--r-- 7,477 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
require File.dirname(__FILE__) + "/spec_helper"

describe TicGitNG::CLI do
  include TicGitNGSpecHelper

  before(:each) do
    @path = setup_new_git_repo
    @orig_test_opts = test_opts
    @ticgitng = TicGitNG.open(@path, @orig_test_opts)
  end

  after(:each) do
    Dir.glob(File.expand_path("~/.ticgit-ng/-tmp*")).each {|file_name| FileUtils.rm_r(file_name, {:force=>true,:secure=>true}) }
    Dir.glob(File.expand_path("~/.ticgit/-tmp*")).each {|file_name| FileUtils.rm_r(file_name, {:force=>true,:secure=>true}) }
    Dir.glob(File.expand_path("/tmp/ticgit-ng-*")).each {|file_name| FileUtils.rm_r(file_name, {:force=>true,:secure=>true}) }
  end

  it "should list the tickets" do
    @ticgitng.tickets.size.should eql(0)
    @ticgitng.ticket_new('my new ticket').should be_an_instance_of(TicGitNG::Ticket)
    @ticgitng.ticket_new('my second ticket').should be_an_instance_of(TicGitNG::Ticket)
    @ticgitng.tickets.size.should eql(2)
    fields = %w[TicId Title State Date Assgn Tags]
    output = []
    # It's unclear why it's necessary to append each line like this, but
    # cli('list') would otherwise return nil. The spec helper probably
    # needs some refactoring.
    cli(@path, 'init','list') do |line|
      output << line
    end
    output.shift.should match ""
    output.shift.should match /#{fields.join( '\s+' )}/
    output.shift.should match /^-+$/
    #check that at least the SHA1 prefix exists
    output.shift[/^[a-z0-9]{6}\s/].should_not == nil
    output.shift[/^[a-z0-9]{6}\s/].should_not == nil
    output.shift.should match ""
  end

  it "should return the same ticket from ticket_show and ticket_new" do
      #FIXME the output of cli(@path,'list') produces a random order
      #- This has to do with a lack of timeskew
      20.times do
        #setup git repo
        git_dir= setup_new_git_repo
        base= TicGitNG.open( git_dir, test_opts )
        base.tickets.size.should eql(0)

        tic1=base.ticket_new('my new ticket', Hash.new, t1=time_skew)
        tic1.should be_an_instance_of(TicGitNG::Ticket)
        tic1.should == base.ticket_show( tic1.ticket_id )

        tic2=base.ticket_new('my second ticket', Hash.new, t2=time_skew)
        tic2.should be_an_instance_of(TicGitNG::Ticket)
        tic2.should == base.ticket_show( tic2.ticket_id )

        tic1.should_not == tic2
        tic1.should_not == base.ticket_show( tic2.ticket_id )

        tic1.title.should == 'my new ticket'
        tic2.title.should == 'my second ticket'
        base.tickets.size.should eql(2)

        if t1>t2
            t=tic2
            tic2=tic1
            tic1=t
        end

        fields = %w[TicId Title State Date Assgn Tags]
        output = []
        # It's unclear why it's necessary to append each line like this, but
        # cli('list') would otherwise return nil. The spec helper probably
        # needs some refactoring.
        cli(git_dir, 'init','list') do |line|
          output << line
        end
        output.shift.should match ""
        output.shift.should match /#{fields.join( '\s+' )}/
        output.shift.should match /^-+$/

        #first ticket
        line=output.shift.split(' ')
        line[0].should match /^[a-z0-9]{6}/
        #This doesn't hinge on t1<t2 because assigned will be
        # the same for both tickets
        a=tic1.assigned
        if a.bytesize > 8
            a="#{a[0, 7]}+"
        end
        line.pop.should == a
        #FIXME if t1<t2, t1, else, t2
        line.pop.should == tic1.opened.strftime('%m/%d')
        line.pop.should == 'open'
        #delete the sha1
        line.shift
        line.join(' ').should == tic1.title

        #second ticket
        line=output.shift.split(' ')
        line[0].should match /^[a-z0-9]{6}/
        a=tic2.assigned
        if a.bytesize > 8
            a="#{a[0, 7]}+"
        end
        line.pop.should == a
        line.pop.should == tic2.opened.strftime('%m/%d')
        line.pop.should == 'open'
        #delete the sha1
        line.shift
        line.join(' ').should == tic2.title
      end
  end

  it "should show a ticket" do
    #FIXME needs time_sku to avoid random failures
    @ticgitng.tickets.size.should eql(0)

    tic1=@ticgitng.ticket_new('my new ticket', Hash.new, t1=time_skew)
    tic1.should be_an_instance_of(TicGitNG::Ticket)
    tic1=@ticgitng.ticket_show(tic1.ticket_id)

    tic2=@ticgitng.ticket_new('my second ticket', Hash.new, t2=time_skew)
    tic2.should be_an_instance_of(TicGitNG::Ticket)
    tic2=@ticgitng.ticket_show(tic2.ticket_id)

    @ticgitng.tickets.size.should eql(2)
    if t1>t2
        t=tic2
        tic2=tic1
        tic1=t
    end

    fields = %w[TicId Title State Date Assgn Tags]
    output = []
    # It's unclear why it's necessary to append each line like this, but
    # cli('list') would otherwise return nil. The spec helper probably
    # needs some refactoring.
    cli(@path, 'init','list') do |line|
      output << line
    end
    output.shift.should match ""
    output.shift.should match /#{fields.join( '\s+' )}/
    output.shift.should match /^-+$/

    #first ticket
    line=output.shift.split(' ')
    line[0].should match /^[a-z0-9]{6}/
    a=tic1.assigned
    if a.bytesize > 8
        a="#{a[0, 7]}+"
    end
    line.pop.should == a
    line.pop.should == tic1.opened.strftime('%m/%d')
    line.pop.should == 'open'
    #delete the sha1
    line.shift
    line.join(' ').should == tic1.title

    #second ticket
    line=output.shift.split(' ')
    line[0].should match /^[a-z0-9]{6}/
    a=tic2.assigned
    if a.bytesize > 8
        a="#{a[0, 7]}+"
    end
    line.pop.should == a
    line.pop.should == tic2.opened.strftime('%m/%d')
    line.pop.should == 'open'
    #delete the sha1
    line.shift
    line.join(' ').should == tic2.title
  end

  it 'displays --help' do
    expected = format_expected(<<-OUT)
Please specify at least one action to execute.

Usage: ti COMMAND [FLAGS] [ARGS]

The available ticgit commands are:
    assign                           Assings a ticket to someone
    attach                           Attach file to ticket
    checkout                         Checkout a ticket
    comment                          Comment on a ticket
    help                             Show help for a ticgit command
    init                             Initialize Ticgit-ng
    list                             List tickets
    new                              Create a new ticket
    points                           Assign points to a ticket
    recent                           List recent activities
    show                             Show a ticket
    state                            Change state of a ticket
    sync                             Sync tickets
    tag                              Modify tags of a ticket

Common options:
    -v, --version                    Show the version number
    -h, --help                       Display this help
    OUT

    cli(@path) do |line|
      line.should == expected.shift
    end
  end

  it 'displays empty list' do
    fields = %w[TicId Title State Date Assgn Tags]
    output = []
    # It's unclear why it's necessary to append each line like this, but
    # cli('list') would otherwise return nil. The spec helper probably
    # needs some refactoring.
    cli(@path, 'init','list') do |line|
      output << line
    end
    output.shift.should match ""
    output.shift.should match /#{fields.join '\s+'}/
    output.shift.should match /^-+$/
  end
end