twig 1.5 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,8 +12,12 @@ describe Twig::CommitTime do
12
12
  end
13
13
 
14
14
  it 'stores a "time ago" string as its shortened version' do
15
+ expect(Twig::CommitTime.new(@time, '1 year, 1 month ago').
16
+ instance_variable_get(:@time_ago)).to eq('1y ago')
15
17
  expect(Twig::CommitTime.new(@time, '2 years, 2 months ago').
16
18
  instance_variable_get(:@time_ago)).to eq('2y ago')
19
+ expect(Twig::CommitTime.new(@time, '1 year ago').
20
+ instance_variable_get(:@time_ago)).to eq('1y ago')
17
21
  expect(Twig::CommitTime.new(@time, '2 years ago').
18
22
  instance_variable_get(:@time_ago)).to eq('2y ago')
19
23
  expect(Twig::CommitTime.new(@time, '2 months ago').
@@ -103,6 +103,28 @@ describe Twig::Display do
103
103
  )
104
104
  end
105
105
 
106
+ it 'only includes certain property names' do
107
+ @twig.set_option(:property_only_name, /foo/)
108
+
109
+ result = @twig.branch_list_headers({})
110
+ result_lines = result.split("\n")
111
+
112
+ expect(result_lines[0]).to include('foo')
113
+ expect(result_lines[0]).not_to include('quux')
114
+ expect(result_lines[0]).to include('branch')
115
+ end
116
+
117
+ it 'excludes certain property names' do
118
+ @twig.set_option(:property_except_name, /foo/)
119
+
120
+ result = @twig.branch_list_headers({})
121
+ result_lines = result.split("\n")
122
+
123
+ expect(result_lines[0]).not_to include('foo')
124
+ expect(result_lines[0]).to include('quux')
125
+ expect(result_lines[0]).to include('branch')
126
+ end
127
+
106
128
  it 'sets a header width' do
107
129
  @twig.set_option(:property_width, :foo => 4)
108
130
 
@@ -127,7 +149,7 @@ describe Twig::Display do
127
149
  end
128
150
 
129
151
  it 'sets a header color' do
130
- result = @twig.branch_list_headers({ :header_color => :green })
152
+ result = @twig.branch_list_headers(:header_color => :green)
131
153
  header_line = result.split("\n").first
132
154
  color = Twig::Display::COLORS[:green]
133
155
  expect(header_line.gsub(/\s/, '')).to eq(
@@ -138,7 +160,7 @@ describe Twig::Display do
138
160
  end
139
161
 
140
162
  it 'sets a header weight' do
141
- result = @twig.branch_list_headers({ :header_weight => :bold })
163
+ result = @twig.branch_list_headers(:header_weight => :bold)
142
164
  header_line = result.split("\n").first
143
165
  weight = Twig::Display::WEIGHTS[:bold]
144
166
  expect(header_line.gsub(/\s/, '')).to eq(
@@ -149,7 +171,7 @@ describe Twig::Display do
149
171
  end
150
172
 
151
173
  it 'sets a header color and weight' do
152
- result = @twig.branch_list_headers({ :header_color => :red, :header_weight => :bold })
174
+ result = @twig.branch_list_headers(:header_color => :red, :header_weight => :bold)
153
175
  header_line = result.split("\n").first
154
176
  color, weight = Twig::Display::COLORS[:red], Twig::Display::WEIGHTS[:bold]
155
177
  expect(header_line.gsub(/\s/, '')).to eq(
@@ -219,6 +241,30 @@ describe Twig::Display do
219
241
  expect(result).to include('line breaks')
220
242
  end
221
243
 
244
+ it 'only includes certain property names' do
245
+ @twig.set_option(:property_only_name, /foo/)
246
+ branch = @current_branch
247
+ expect(branch).to receive(:get_properties).
248
+ with(['foo']).
249
+ and_return('foo' => 'foo!')
250
+
251
+ result = @twig.branch_list_line(branch)
252
+
253
+ expect(result).to include('foo!')
254
+ end
255
+
256
+ it 'excludes certain property names' do
257
+ @twig.set_option(:property_except_name, /foo/)
258
+ branch = @current_branch
259
+ expect(branch).to receive(:get_properties).
260
+ with(['bar']).
261
+ and_return('bar' => 'bar!')
262
+
263
+ result = @twig.branch_list_line(branch)
264
+
265
+ expect(result).to include('bar!')
266
+ end
267
+
222
268
  it 'returns a line with custom column widths' do
223
269
  branch = @other_branch
224
270
  @twig.set_option(:property_width, :foo => 5)
@@ -274,8 +320,8 @@ describe Twig::Display do
274
320
 
275
321
  describe '#branches_json' do
276
322
  before :each do
277
- @commit_time = Twig::CommitTime.new(Time.now, '')
278
- allow(@commit_time).to receive(:to_s).and_return('2000-01-01')
323
+ @property_names = %w[foo bar]
324
+ allow(@twig).to receive(:property_names).and_return(@property_names)
279
325
  end
280
326
 
281
327
  it 'returns JSON for an array of branches' do
@@ -288,8 +334,12 @@ describe Twig::Display do
288
334
  { 'name' => 'branch2' }
289
335
  ]
290
336
  expect(@twig).to receive(:branches).and_return(branches)
291
- expect(branches[0]).to receive(:to_hash).and_return(branch_hashes[0])
292
- expect(branches[1]).to receive(:to_hash).and_return(branch_hashes[1])
337
+ expect(branches[0]).to receive(:to_hash).
338
+ with(@property_names).
339
+ and_return(branch_hashes[0])
340
+ expect(branches[1]).to receive(:to_hash).
341
+ with(@property_names).
342
+ and_return(branch_hashes[1])
293
343
 
294
344
  result = @twig.branches_json
295
345
 
@@ -213,7 +213,7 @@ describe Twig::Options do
213
213
 
214
214
  it 'reads and sets a single option' do
215
215
  path = Twig::CONFIG_PATH
216
- allow(@twig).to receive(:all_branch_names) { ['test'] }
216
+ allow(Twig::Branch).to receive(:all_branch_names) { ['test'] }
217
217
  expect(@twig).to receive(:readable_config_file_path).and_return(path)
218
218
  expect(@twig).to receive(:parse_config_file).with(path).and_return(
219
219
  'branch' => 'test'
@@ -227,7 +227,7 @@ describe Twig::Options do
227
227
 
228
228
  it 'reads and sets multiple options' do
229
229
  path = Twig::CONFIG_PATH
230
- allow(@twig).to receive(:all_branch_names) { ['test'] }
230
+ allow(Twig::Branch).to receive(:all_branch_names) { ['test'] }
231
231
  expect(@twig).to receive(:readable_config_file_path).and_return(path)
232
232
  expect(@twig).to receive(:parse_config_file).with(path).and_return(
233
233
  # Filtering branches:
@@ -239,10 +239,12 @@ describe Twig::Options do
239
239
  'only-foo' => 'test-only-foo',
240
240
 
241
241
  # Displaying branches:
242
- 'format' => 'json',
243
- 'header-style' => 'green bold',
244
- 'reverse' => 'true',
245
- 'foo-width' => '4',
242
+ 'format' => 'json',
243
+ 'except-property' => 'foo',
244
+ 'only-property' => 'bar',
245
+ 'header-style' => 'green bold',
246
+ 'reverse' => 'true',
247
+ 'foo-width' => '4',
246
248
 
247
249
  # GitHub integration:
248
250
  'github-api-uri-prefix' => 'https://github-enterprise.example.com/api/v3',
@@ -263,6 +265,8 @@ describe Twig::Options do
263
265
  expect(@twig.options[:max_days_old]).to be_nil
264
266
  expect(@twig.options[:property_except]).to be_nil
265
267
  expect(@twig.options[:property_only]).to be_nil
268
+ expect(@twig.options[:property_except_name]).to be_nil
269
+ expect(@twig.options[:property_only_name]).to be_nil
266
270
  expect(@twig.options[:property_width]).to be_nil
267
271
  expect(@twig.options[:reverse]).to be_nil
268
272
 
@@ -287,6 +291,8 @@ describe Twig::Options do
287
291
  :branch => /test-only-branch/,
288
292
  :foo => /test-only-foo/
289
293
  )
294
+ expect(@twig.options[:property_except_name]).to eq(/foo/)
295
+ expect(@twig.options[:property_only_name]).to eq(/bar/)
290
296
  expect(@twig.options[:property_width]).to eq(:foo => 4)
291
297
  expect(@twig.options[:reverse]).to be_true
292
298
  end
@@ -300,7 +306,7 @@ describe Twig::Options do
300
306
 
301
307
  it 'succeeds' do
302
308
  branch_name = 'foo'
303
- expect(@twig).to receive(:all_branch_names).and_return(%[foo bar])
309
+ expect(Twig::Branch).to receive(:all_branch_names).and_return(%[foo bar])
304
310
 
305
311
  @twig.set_option(:branch, branch_name)
306
312
 
@@ -309,7 +315,7 @@ describe Twig::Options do
309
315
 
310
316
  it 'fails if the branch is unknown' do
311
317
  branch_name = 'foo'
312
- expect(@twig).to receive(:all_branch_names).and_return([])
318
+ expect(Twig::Branch).to receive(:all_branch_names).and_return([])
313
319
  expect(@twig).to receive(:abort) do |message|
314
320
  expect(message).to include(%{branch `#{branch_name}` could not be found})
315
321
  end
@@ -390,6 +396,18 @@ describe Twig::Options do
390
396
  expect(@twig.options[:property_only]).to eq(:branch => /important_prefix_/)
391
397
  end
392
398
 
399
+ it 'sets a :property_except_name option' do
400
+ expect(@twig.options[:property_except_name]).to be_nil
401
+ @twig.set_option(:property_except_name, /foo/)
402
+ expect(@twig.options[:property_except_name]).to eq(/foo/)
403
+ end
404
+
405
+ it 'sets a :property_only_name option' do
406
+ expect(@twig.options[:property_only_name]).to be_nil
407
+ @twig.set_option(:property_only_name, /foo/)
408
+ expect(@twig.options[:property_only_name]).to eq(/foo/)
409
+ end
410
+
393
411
  it 'sets a :property_width option' do
394
412
  width = 10
395
413
  expect(@twig).to receive(:set_property_width_option).with(width)
@@ -430,7 +448,6 @@ describe Twig::Options do
430
448
 
431
449
  describe '#set_header_style_option' do
432
450
  before :each do
433
- # Preconditions:
434
451
  expect(@twig.options[:header_color]).to eq(Twig::DEFAULT_HEADER_COLOR)
435
452
  expect(@twig.options[:header_weight]).to be_nil
436
453
  end
@@ -519,7 +536,7 @@ describe Twig::Options do
519
536
  end
520
537
 
521
538
  it 'succeeds' do
522
- @twig.set_option(:property_width, :foo => '20', :bar => '40')
539
+ @twig.set_property_width_option(:foo => '20', :bar => '40')
523
540
  expect(@twig.options[:property_width]).to eq(:foo => 20, :bar => 40)
524
541
  end
525
542
 
@@ -531,11 +548,11 @@ describe Twig::Options do
531
548
  end
532
549
 
533
550
  begin
534
- @twig.set_option(:property_width, :branch => width)
551
+ @twig.set_property_width_option(:branch => width)
535
552
  rescue SystemExit => exception
536
553
  end
537
554
 
538
- expect(@twig.options[:property_width]).to be_nil
555
+ expect(@twig.options[:property_width]).to eq({})
539
556
  end
540
557
 
541
558
  it 'fails if width is below minimum value' do
@@ -548,11 +565,11 @@ describe Twig::Options do
548
565
  end
549
566
 
550
567
  begin
551
- @twig.set_option(:property_width, :x => width)
568
+ @twig.set_property_width_option(:x => width)
552
569
  rescue SystemExit => exception
553
570
  end
554
571
 
555
- expect(@twig.options[:property_width]).to be_nil
572
+ expect(@twig.options[:property_width]).to eq({})
556
573
  end
557
574
 
558
575
  it 'fails if width is below width of property name' do
@@ -565,11 +582,11 @@ describe Twig::Options do
565
582
  end
566
583
 
567
584
  begin
568
- @twig.set_option(:property_width, property_name => width)
585
+ @twig.set_property_width_option(property_name => width)
569
586
  rescue SystemExit => exception
570
587
  end
571
588
 
572
- expect(@twig.options[:property_width]).to be_nil
589
+ expect(@twig.options[:property_width]).to eq({})
573
590
  end
574
591
  end
575
592
 
@@ -32,6 +32,22 @@ describe Twig do
32
32
  :header_color => Twig::DEFAULT_HEADER_COLOR
33
33
  )
34
34
  end
35
+
36
+ it 'reads config files and command-line options when `:read_options` is true' do
37
+ expect_any_instance_of(Twig).to receive(:read_config_file!)
38
+ expect_any_instance_of(Twig).to receive(:read_cli_options!)
39
+
40
+ Twig.new(:read_options => true)
41
+ end
42
+
43
+ it 'does not read config files or command-line options when `:read_options` is falsy' do
44
+ expect_any_instance_of(Twig).not_to receive(:read_config_file!)
45
+ expect_any_instance_of(Twig).not_to receive(:read_cli_options!)
46
+
47
+ Twig.new(:read_options => false)
48
+ Twig.new(:read_options => nil)
49
+ Twig.new
50
+ end
35
51
  end
36
52
 
37
53
  describe '#current_branch_name' do
@@ -47,52 +63,23 @@ describe Twig do
47
63
  end
48
64
  end
49
65
 
50
- describe '#all_branches' do
66
+ describe '#target_branch_name' do
51
67
  before :each do
52
- @branch_names = %w[
53
- fix_some_of_the_things
54
- fix_some_other_of_the_things
55
- fix_nothing
56
- ]
57
- @commit_time_strings = ['2001-01-01', '2002-02-02', '2003-03-03' ]
58
- @commit_time_agos = ['111 days ago', '2 months ago', '3 years, 3 months ago']
59
- @command =
60
- %{git for-each-ref #{Twig::REF_PREFIX} --format="#{Twig::REF_FORMAT}"}
61
-
62
- @branch_tuples = (0..2).map do |i|
63
- [
64
- @branch_names[i],
65
- @commit_time_strings[i],
66
- @commit_time_agos[i]
67
- ].join(Twig::REF_FORMAT_SEPARATOR)
68
- end.join("\n")
68
+ @current_branch_name = 'current-branch'
69
+ @twig = Twig.new
70
+ allow(@twig).to receive(:current_branch_name).and_return(@current_branch_name)
69
71
  end
70
72
 
71
- it 'returns an array of branches' do
72
- expect(Twig).to receive(:run).with(@command).and_return(@branch_tuples)
73
- twig = Twig.new
74
-
75
- branches = twig.all_branches
73
+ it 'returns the branch specified in options' do
74
+ feature_branch_name = 'feature-branch'
75
+ expect(Twig::Branch).to receive(:all_branch_names).and_return([feature_branch_name])
76
+ @twig.set_option(:branch, feature_branch_name)
76
77
 
77
- expect(branches[0].name).to eq(@branch_names[0])
78
- expect(branches[0].last_commit_time.to_s).to match(
79
- %r{#{@commit_time_strings[0]} .* \(111d ago\)}
80
- )
81
- expect(branches[1].name).to eq(@branch_names[1])
82
- expect(branches[1].last_commit_time.to_s).to match(
83
- %r{#{@commit_time_strings[1]} .* \(2mo ago\)}
84
- )
85
- expect(branches[2].name).to eq(@branch_names[2])
86
- expect(branches[2].last_commit_time.to_s).to match(
87
- %r{#{@commit_time_strings[2]} .* \(3y ago\)}
88
- )
78
+ expect(@twig.target_branch_name).to eq(feature_branch_name)
89
79
  end
90
80
 
91
- it 'memoizes the result' do
92
- expect(Twig).to receive(:run).with(@command).once.and_return(@branch_tuples)
93
- twig = Twig.new
94
-
95
- 2.times { twig.all_branches }
81
+ it 'returns the current branch by default' do
82
+ expect(@twig.target_branch_name).to eq(@current_branch_name)
96
83
  end
97
84
  end
98
85
 
@@ -117,7 +104,7 @@ describe Twig do
117
104
  Twig::Branch.new(branch_names[2], :last_commit_time => commit_times[2]),
118
105
  Twig::Branch.new(branch_names[3], :last_commit_time => commit_times[3])
119
106
  ]
120
- allow(@twig).to receive(:all_branches) { @branches }
107
+ allow(Twig::Branch).to receive(:all_branches) { @branches }
121
108
  end
122
109
 
123
110
  it 'returns all branches' do
@@ -193,14 +180,30 @@ describe Twig do
193
180
  end
194
181
  end
195
182
 
196
- describe '#all_branch_names' do
197
- it 'returns an array of all branch names' do
198
- twig = Twig.new
199
- branch_names = %w[foo bar baz]
200
- branches = branch_names.map { |name| Twig::Branch.new(name) }
201
- expect(twig).to receive(:all_branches).and_return(branches)
183
+ describe '#property_names' do
184
+ before :each do
185
+ @twig = Twig.new
186
+ property_names = %w[foo bar baz]
187
+ expect(Twig::Branch).to receive(:all_property_names).and_return(property_names)
188
+ end
189
+
190
+ it 'returns an array of all property names' do
191
+ property_names = @twig.property_names
192
+ expect(property_names).to eq(%w[foo bar baz])
193
+ end
194
+
195
+ it 'returns an array with only certain property names' do
196
+ @twig.set_option(:property_only_name, /ba/)
197
+ property_names = @twig.property_names
198
+
199
+ expect(property_names).to eq(%w[bar baz])
200
+ end
201
+
202
+ it 'returns an array without certain property names' do
203
+ @twig.set_option(:property_except_name, /ba/)
204
+ property_names = @twig.property_names
202
205
 
203
- expect(twig.all_branch_names).to eq(branch_names)
206
+ expect(property_names).to eq(%w[foo])
204
207
  end
205
208
  end
206
209
 
@@ -240,7 +243,7 @@ describe Twig do
240
243
  end
241
244
 
242
245
  it 'returns a message if all branches were filtered out by options' do
243
- allow(@twig).to receive(:all_branches) { %w[foo bar] }
246
+ allow(Twig::Branch).to receive(:all_branches) { %w[foo bar] }
244
247
  allow(@twig).to receive(:branches) { [] }
245
248
 
246
249
  expect(@twig.list_branches).to include(
@@ -249,7 +252,7 @@ describe Twig do
249
252
  end
250
253
 
251
254
  it 'returns a message if the repo has no branches' do
252
- allow(@twig).to receive(:all_branches) { [] }
255
+ allow(Twig::Branch).to receive(:all_branches) { [] }
253
256
  allow(@twig).to receive(:branches) { [] }
254
257
 
255
258
  expect(@twig.list_branches).to include('This repository has no branches')
@@ -14,18 +14,24 @@ Gem::Specification.new do |spec|
14
14
  spec.summary = %{Your personal Git branch assistant.}
15
15
  spec.description = %w[
16
16
  Twig is your personal Git branch assistant. It's a command-line tool for
17
- listing your most recent branches, and for remembering each branch's ticket
18
- ids, todos, and other details. Twig supports subcommands for managing
19
- branches however you want. It's flexible enough to fit your every Git
20
- workflow, and will save you a ton of time.
17
+ listing your most recent branches, and for remembering branch details for
18
+ you, like issue tracker ids and todos. It supports subcommands, like
19
+ automatically fetching statuses from your issue tracking system. It's
20
+ flexible enough to fit your everyday Git workflow, and will save you a ton
21
+ of time.
21
22
  ].join(' ')
22
23
  spec.post_install_message =
23
24
  "\n**************************************************************" <<
24
25
  "\n* *" <<
25
26
  "\n* Welcome to Twig! *" <<
26
27
  "\n* *" <<
27
- "\n* To get started, run `twig` to list your Git branches, and *" <<
28
- "\n* `twig --help` for more info. *" <<
28
+ "\n* Quick start: *" <<
29
+ "\n* *" <<
30
+ "\n* 1. Run `twig init` to set up tab completion. *" <<
31
+ "\n* 2. Run `twig` to list your Git branches. *" <<
32
+ "\n* *" <<
33
+ "\n* For more info, run `twig --help` or visit *" <<
34
+ "\n* #{sprintf('%-59s', Twig::HOMEPAGE) }*" <<
29
35
  "\n* *" <<
30
36
  "\n**************************************************************" <<
31
37
  "\n\n"
@@ -36,8 +42,9 @@ Gem::Specification.new do |spec|
36
42
  spec.test_files = spec.files.grep(%r{^spec/})
37
43
 
38
44
  spec.required_ruby_version = '>= 1.8.7'
39
- spec.add_runtime_dependency 'json', '~> 1.7.5'
40
- spec.add_runtime_dependency 'launchy', '~> 2.3.0'
41
- spec.add_development_dependency 'rake', '~> 0.9.2'
42
- spec.add_development_dependency 'rspec', '~> 2.14.1'
45
+ spec.add_runtime_dependency 'json', '~> 1.7.5'
46
+ spec.add_runtime_dependency 'launchy', '~> 2.3.0'
47
+ spec.add_development_dependency 'rake', '~> 0.9.2'
48
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
49
+ spec.add_development_dependency 'rspec-radar', '~> 0.1.0'
43
50
  end