twig 1.6 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,37 @@ describe Twig::Display do
5
5
  @twig = Twig.new
6
6
  end
7
7
 
8
+ describe '.unformat_string' do
9
+ it 'unformats a plain text string' do
10
+ string = 'foo'
11
+ expect(Twig::Display.unformat_string(string)).to eq(string)
12
+ end
13
+
14
+ it 'unformats a string with color' do
15
+ string = 'foo'
16
+ formatted_string = @twig.format_string(string, :color => :red)
17
+ expect(formatted_string.size).to be > 3
18
+
19
+ expect(Twig::Display.unformat_string(formatted_string)).to eq(string)
20
+ end
21
+
22
+ it 'unformats a string with weight' do
23
+ string = 'foo'
24
+ formatted_string = @twig.format_string(string, :weight => :bold)
25
+ expect(formatted_string.size).to be > 3
26
+
27
+ expect(Twig::Display.unformat_string(formatted_string)).to eq(string)
28
+ end
29
+
30
+ it 'unformats a string with color and weight' do
31
+ string = 'foo'
32
+ formatted_string = @twig.format_string(string, :color => :red, :weight => :bold)
33
+ expect(formatted_string.size).to be > 3
34
+
35
+ expect(Twig::Display.unformat_string(formatted_string)).to eq(string)
36
+ end
37
+ end
38
+
8
39
  describe '#column' do
9
40
  it 'returns a string with an exact fixed width' do
10
41
  expect(@twig.column('foo', :width => 8)).to eq('foo' + (' ' * 5))
@@ -153,8 +184,8 @@ describe Twig::Display do
153
184
  header_line = result.split("\n").first
154
185
  color = Twig::Display::COLORS[:green]
155
186
  expect(header_line.gsub(/\s/, '')).to eq(
156
- "\e[#{color}mfoo\e[0m" <<
157
- "\e[#{color}mquux\e[0m" <<
187
+ "\e[#{color}mfoo\e[0m" \
188
+ "\e[#{color}mquux\e[0m" \
158
189
  "\e[#{color}mbranch\e[0m"
159
190
  )
160
191
  end
@@ -164,8 +195,8 @@ describe Twig::Display do
164
195
  header_line = result.split("\n").first
165
196
  weight = Twig::Display::WEIGHTS[:bold]
166
197
  expect(header_line.gsub(/\s/, '')).to eq(
167
- "\e[#{weight}mfoo\e[0m" <<
168
- "\e[#{weight}mquux\e[0m" <<
198
+ "\e[#{weight}mfoo\e[0m" \
199
+ "\e[#{weight}mquux\e[0m" \
169
200
  "\e[#{weight}mbranch\e[0m"
170
201
  )
171
202
  end
@@ -175,8 +206,8 @@ describe Twig::Display do
175
206
  header_line = result.split("\n").first
176
207
  color, weight = Twig::Display::COLORS[:red], Twig::Display::WEIGHTS[:bold]
177
208
  expect(header_line.gsub(/\s/, '')).to eq(
178
- "\e[#{color};#{weight}mfoo\e[0m" <<
179
- "\e[#{color};#{weight}mquux\e[0m" <<
209
+ "\e[#{color};#{weight}mfoo\e[0m" \
210
+ "\e[#{color};#{weight}mquux\e[0m" \
180
211
  "\e[#{color};#{weight}mbranch\e[0m"
181
212
  )
182
213
  end
@@ -194,7 +225,7 @@ describe Twig::Display do
194
225
  allow(@other_branch).to receive(:get_properties) do
195
226
  { 'foo' => 'foo!', 'bar' => 'bar!' }
196
227
  end
197
- commit_time = Twig::CommitTime.new(Time.now, '')
228
+ commit_time = Twig::CommitTime.new(Time.now)
198
229
  expect(commit_time).to receive(:to_s).and_return('2000-01-01')
199
230
  allow(@current_branch).to receive(:last_commit_time) { commit_time }
200
231
  allow(@other_branch).to receive(:last_commit_time) { commit_time }
@@ -286,12 +317,11 @@ describe Twig::Display do
286
317
  end
287
318
 
288
319
  it 'returns a line for the current branch' do
289
- indicator = Twig::Display::CURRENT_BRANCH_INDICATOR
290
- branch = @current_branch
291
- branch_regexp = /#{Regexp.escape(indicator)}#{Regexp.escape(branch.name)}/
320
+ indicator = Twig::Display::CURRENT_BRANCH_INDICATOR
321
+ branch = @current_branch
292
322
 
293
323
  result = @twig.branch_list_line(branch)
294
- unformatted_result = @twig.unformat_string(result)
324
+ unformatted_result = Twig::Display.unformat_string(result)
295
325
 
296
326
  column_gutter = @twig.column_gutter
297
327
  expect(unformatted_result).to eq(
@@ -303,6 +333,7 @@ describe Twig::Display do
303
333
  end
304
334
 
305
335
  it 'returns a line for a branch other than the current branch' do
336
+ no_indicator = ' ' * (Twig::Display::CURRENT_BRANCH_INDICATOR.size)
306
337
  branch = @other_branch
307
338
 
308
339
  result = @twig.branch_list_line(branch)
@@ -312,7 +343,7 @@ describe Twig::Display do
312
343
  '2000-01-01' + (' ' * 25) + column_gutter +
313
344
  'foo!' + (' ' * 12) + column_gutter +
314
345
  'bar!' + (' ' * 12) + column_gutter +
315
- ' ' + 'other...'
346
+ no_indicator + 'other...'
316
347
  )
317
348
  end
318
349
  end
@@ -353,11 +384,32 @@ describe Twig::Display do
353
384
  end
354
385
  end
355
386
 
387
+ describe '#format_strings?' do
388
+ before :each do
389
+ @twig = Twig.new
390
+ end
391
+
392
+ it 'returns false if using Windows' do
393
+ expect(Twig::System).to receive(:windows?) { true }
394
+ expect(@twig.format_strings?).to eql(false)
395
+ end
396
+
397
+ it 'returns true if expected conditions pass' do
398
+ expect(Twig::System).to receive(:windows?) { false }
399
+ expect(@twig.format_strings?).to eql(true)
400
+ end
401
+ end
402
+
356
403
  describe '#format_string' do
357
404
  it 'returns a plain string' do
358
405
  expect(@twig.format_string('foo', {})).to eq('foo')
359
406
  end
360
407
 
408
+ it 'returns a plain string if formatting is disabled' do
409
+ expect(@twig).to receive(:format_strings?) { false }
410
+ expect(@twig.format_string('foo', :color => :red)).to eql('foo')
411
+ end
412
+
361
413
  it 'returns a string with a color code' do
362
414
  expect(@twig.format_string('foo', :color => :red)).to eq(
363
415
  "\e[#{Twig::Display::COLORS[:red]}mfoo\e[0m"
@@ -371,43 +423,12 @@ describe Twig::Display do
371
423
  end
372
424
 
373
425
  it 'returns a string with a color and weight code 'do
374
- color_code = Twig::Display::COLORS[:red]
375
- weight_code = Twig::Display::WEIGHTS[:bold]
376
-
377
- expect(@twig.format_string('foo', :color => :red, :weight => :bold)).to eq(
378
- "\e[#{color_code};#{weight_code}mfoo\e[0m"
379
- )
380
- end
381
- end
382
-
383
- describe '#unformat_string' do
384
- it 'unformats a plain text string' do
385
- string = 'foo'
386
- expect(@twig.unformat_string(string)).to eq(string)
387
- end
388
-
389
- it 'unformats a string with color' do
390
- string = 'foo'
391
- formatted_string = @twig.format_string(string, :color => :red)
392
- expect(formatted_string.size).to be > 3
426
+ color_code = Twig::Display::COLORS[:red]
427
+ weight_code = Twig::Display::WEIGHTS[:bold]
393
428
 
394
- expect(@twig.unformat_string(formatted_string)).to eq(string)
395
- end
396
-
397
- it 'unformats a string with weight' do
398
- string = 'foo'
399
- formatted_string = @twig.format_string(string, :weight => :bold)
400
- expect(formatted_string.size).to be > 3
401
-
402
- expect(@twig.unformat_string(formatted_string)).to eq(string)
403
- end
404
-
405
- it 'unformats a string with color and weight' do
406
- string = 'foo'
407
- formatted_string = @twig.format_string(string, :color => :red, :weight => :bold)
408
- expect(formatted_string.size).to be > 3
409
-
410
- expect(@twig.unformat_string(formatted_string)).to eq(string)
429
+ expect(@twig.format_string('foo', :color => :red, :weight => :bold)).to eq(
430
+ "\e[#{color_code};#{weight_code}mfoo\e[0m"
431
+ )
411
432
  end
412
433
  end
413
434
  end
@@ -26,7 +26,7 @@ describe Twig::GithubRepo do
26
26
  block_has_run = true
27
27
  end
28
28
 
29
- expect(block_has_run).to be_true
29
+ expect(block_has_run).to eql(true)
30
30
  end
31
31
 
32
32
  it 'aborts if this is not a Git repo' do
@@ -35,7 +35,7 @@ describe Twig::GithubRepo do
35
35
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
36
36
  allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
37
37
  allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
38
- expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |message|
38
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
39
39
  expect(message).to include('not a git repository')
40
40
  end
41
41
 
@@ -47,7 +47,9 @@ describe Twig::GithubRepo do
47
47
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { '' }
48
48
  allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
49
49
  allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
50
- expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
50
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
51
+ expect(message).to include('GitHub repository')
52
+ end
51
53
 
52
54
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
53
55
  end
@@ -58,7 +60,9 @@ describe Twig::GithubRepo do
58
60
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
59
61
  allow_any_instance_of(Twig::GithubRepo).to receive(:username) { '' }
60
62
  allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
61
- expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
63
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
64
+ expect(message).to include('GitHub repository')
65
+ end
62
66
 
63
67
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
64
68
  end
@@ -69,7 +73,9 @@ describe Twig::GithubRepo do
69
73
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
70
74
  allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
71
75
  allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { '' }
72
- expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
76
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
77
+ expect(message).to include('GitHub repository')
78
+ end
73
79
 
74
80
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
75
81
  end
@@ -80,7 +86,9 @@ describe Twig::GithubRepo do
80
86
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
81
87
  allow_any_instance_of(Twig::GithubRepo).to receive(:username) { 'username' }
82
88
  allow_any_instance_of(Twig::GithubRepo).to receive(:repository) { 'repository' }
83
- expect_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
89
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
90
+ expect(message).to include('GitHub repository')
91
+ end
84
92
 
85
93
  Twig::GithubRepo.new { |gh_repo| } # Do nothing
86
94
  end
@@ -145,7 +153,7 @@ describe Twig::GithubRepo do
145
153
  is_github_repo = gh_repo.github_repo?
146
154
  end
147
155
 
148
- expect(is_github_repo).to be_true
156
+ expect(is_github_repo).to eql(true)
149
157
  end
150
158
  end
151
159
 
@@ -161,7 +169,7 @@ describe Twig::GithubRepo do
161
169
  is_github_repo = gh_repo.github_repo?
162
170
  end
163
171
 
164
- expect(is_github_repo).to be_true
172
+ expect(is_github_repo).to eql(true)
165
173
  end
166
174
  end
167
175
 
@@ -177,7 +185,7 @@ describe Twig::GithubRepo do
177
185
  is_github_repo = gh_repo.github_repo?
178
186
  end
179
187
 
180
- expect(is_github_repo).to be_true
188
+ expect(is_github_repo).to eql(true)
181
189
  end
182
190
  end
183
191
 
@@ -185,7 +193,9 @@ describe Twig::GithubRepo do
185
193
  before :each do
186
194
  origin_url = @generic_https_url
187
195
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
188
- allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
196
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
197
+ expect(message).to include('GitHub repository')
198
+ end
189
199
  end
190
200
 
191
201
  it 'returns false' do
@@ -194,7 +204,7 @@ describe Twig::GithubRepo do
194
204
  is_github_repo = gh_repo.github_repo?
195
205
  end
196
206
 
197
- expect(is_github_repo).to be_false
207
+ expect(is_github_repo).to eql(false)
198
208
  end
199
209
  end
200
210
 
@@ -202,7 +212,9 @@ describe Twig::GithubRepo do
202
212
  before :each do
203
213
  origin_url = @generic_git_read_only_url
204
214
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
205
- allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
215
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
216
+ expect(message).to include('GitHub repository')
217
+ end
206
218
  end
207
219
 
208
220
  it 'returns false' do
@@ -211,7 +223,7 @@ describe Twig::GithubRepo do
211
223
  is_github_repo = gh_repo.github_repo?
212
224
  end
213
225
 
214
- expect(is_github_repo).to be_false
226
+ expect(is_github_repo).to eql(false)
215
227
  end
216
228
  end
217
229
 
@@ -219,7 +231,9 @@ describe Twig::GithubRepo do
219
231
  before :each do
220
232
  origin_url = @generic_ssh_read_write_url
221
233
  allow_any_instance_of(Twig::GithubRepo).to receive(:origin_url) { origin_url }
222
- allow_any_instance_of(Twig::GithubRepo).to receive(:abort_for_non_github_repo)
234
+ expect_any_instance_of(Twig::GithubRepo).to receive(:abort) do |repo, message|
235
+ expect(message).to include('GitHub repository')
236
+ end
223
237
  end
224
238
 
225
239
  it 'returns false' do
@@ -228,7 +242,7 @@ describe Twig::GithubRepo do
228
242
  is_github_repo = gh_repo.github_repo?
229
243
  end
230
244
 
231
- expect(is_github_repo).to be_false
245
+ expect(is_github_repo).to eql(false)
232
246
  end
233
247
  end
234
248
  end
@@ -13,7 +13,7 @@ describe Twig::Options do
13
13
 
14
14
  context 'with a config path that exists' do
15
15
  before :each do
16
- expect(File).to receive(:exists?).with(Twig::CONFIG_PATH).and_return(true)
16
+ expect(File).to receive(:exist?).with(Twig::CONFIG_PATH).and_return(true)
17
17
  end
18
18
 
19
19
  it 'returns the config path if is readable' do
@@ -41,14 +41,14 @@ describe Twig::Options do
41
41
 
42
42
  context 'with a config path that does not exist' do
43
43
  before :each do
44
- expect(File).to receive(:exists?).with(Twig::CONFIG_PATH).and_return(false)
44
+ expect(File).to receive(:exist?).with(Twig::CONFIG_PATH).and_return(false)
45
45
  expect(File).to receive(:expand_path).with(Twig::DEPRECATED_CONFIG_PATH).
46
46
  and_return(Twig::DEPRECATED_CONFIG_PATH)
47
47
  end
48
48
 
49
49
  it 'prints a deprecation warning and returns the deprecated config path if it exists and is readable' do
50
50
  path = Twig::DEPRECATED_CONFIG_PATH
51
- expect(File).to receive(:exists?).with(path).and_return(true)
51
+ expect(File).to receive(:exist?).with(path).and_return(true)
52
52
  expect(File).to receive(:readable?).with(path).and_return(true)
53
53
  expect($stderr).to receive(:puts) do |message|
54
54
  expect(message).to match(/^DEPRECATED:/)
@@ -63,7 +63,7 @@ describe Twig::Options do
63
63
 
64
64
  it 'prints a deprecation warning and returns nil if the deprecated config path exists but is not readable' do
65
65
  path = Twig::DEPRECATED_CONFIG_PATH
66
- expect(File).to receive(:exists?).with(path).and_return(true)
66
+ expect(File).to receive(:exist?).with(path).and_return(true)
67
67
  expect(File).to receive(:readable?).with(path).and_return(false)
68
68
  expect($stderr).to receive(:puts) do |message|
69
69
  expect(message).to match(/^DEPRECATED:/)
@@ -78,7 +78,7 @@ describe Twig::Options do
78
78
 
79
79
  it 'returns nil if the deprecated config path does not exist' do
80
80
  path = Twig::DEPRECATED_CONFIG_PATH
81
- expect(File).to receive(:exists?).with(path).and_return(false)
81
+ expect(File).to receive(:exist?).with(path).and_return(false)
82
82
 
83
83
  result = @twig.readable_config_file_path
84
84
 
@@ -248,7 +248,10 @@ describe Twig::Options do
248
248
 
249
249
  # GitHub integration:
250
250
  'github-api-uri-prefix' => 'https://github-enterprise.example.com/api/v3',
251
- 'github-uri-prefix' => 'https://github-enterprise.example.com'
251
+ 'github-uri-prefix' => 'https://github-enterprise.example.com',
252
+
253
+ # Subcommands:
254
+ 'twig-rebase-autoconfirm' => 'true'
252
255
  )
253
256
 
254
257
  # Check preconditions
@@ -269,6 +272,7 @@ describe Twig::Options do
269
272
  expect(@twig.options[:property_only_name]).to be_nil
270
273
  expect(@twig.options[:property_width]).to be_nil
271
274
  expect(@twig.options[:reverse]).to be_nil
275
+ expect(@twig.options[:twig_rebase_autoconfirm]).to be_nil
272
276
 
273
277
  @twig.read_config_file!
274
278
 
@@ -294,7 +298,8 @@ describe Twig::Options do
294
298
  expect(@twig.options[:property_except_name]).to eq(/foo/)
295
299
  expect(@twig.options[:property_only_name]).to eq(/bar/)
296
300
  expect(@twig.options[:property_width]).to eq(:foo => 4)
297
- expect(@twig.options[:reverse]).to be_true
301
+ expect(@twig.options[:reverse]).to eql(true)
302
+ expect(@twig.options[:twig_rebase_autoconfirm]).to eql(true)
298
303
  end
299
304
  end
300
305
 
@@ -306,7 +311,7 @@ describe Twig::Options do
306
311
 
307
312
  it 'succeeds' do
308
313
  branch_name = 'foo'
309
- expect(Twig::Branch).to receive(:all_branch_names).and_return(%[foo bar])
314
+ expect(Twig::Branch).to receive(:all_branch_names).and_return(%w[foo bar])
310
315
 
311
316
  @twig.set_option(:branch, branch_name)
312
317
 
@@ -426,7 +431,7 @@ describe Twig::Options do
426
431
 
427
432
  @twig.set_option(:reverse, input)
428
433
 
429
- expect(@twig.options[:reverse]).to be_true
434
+ expect(@twig.options[:reverse]).to eql(true)
430
435
  end
431
436
 
432
437
  it 'sets the option to false when input is not truthy' do
@@ -435,7 +440,31 @@ describe Twig::Options do
435
440
 
436
441
  @twig.set_option(:reverse, input)
437
442
 
438
- expect(@twig.options[:reverse]).to be_false
443
+ expect(@twig.options[:reverse]).to eql(false)
444
+ end
445
+ end
446
+
447
+ context 'when setting a :twig_rebase_autoconfirm option' do
448
+ before :each do
449
+ expect(@twig.options[:twig_rebase_autoconfirm]).to be_nil
450
+ end
451
+
452
+ it 'sets the option to true when input is truthy' do
453
+ input = 'yes'
454
+ expect(Twig::Util).to receive(:truthy?).with(input).and_call_original
455
+
456
+ @twig.set_option(:twig_rebase_autoconfirm, input)
457
+
458
+ expect(@twig.options[:twig_rebase_autoconfirm]).to eql(true)
459
+ end
460
+
461
+ it 'sets the option to false when input is not truthy' do
462
+ input = 'blargh'
463
+ expect(Twig::Util).to receive(:truthy?).with(input).and_call_original
464
+
465
+ @twig.set_option(:twig_rebase_autoconfirm, input)
466
+
467
+ expect(@twig.options[:twig_rebase_autoconfirm]).to eql(false)
439
468
  end
440
469
  end
441
470
 
@@ -549,7 +578,7 @@ describe Twig::Options do
549
578
 
550
579
  begin
551
580
  @twig.set_property_width_option(:branch => width)
552
- rescue SystemExit => exception
581
+ rescue SystemExit
553
582
  end
554
583
 
555
584
  expect(@twig.options[:property_width]).to eq({})
@@ -566,7 +595,7 @@ describe Twig::Options do
566
595
 
567
596
  begin
568
597
  @twig.set_property_width_option(:x => width)
569
- rescue SystemExit => exception
598
+ rescue SystemExit
570
599
  end
571
600
 
572
601
  expect(@twig.options[:property_width]).to eq({})
@@ -583,7 +612,7 @@ describe Twig::Options do
583
612
 
584
613
  begin
585
614
  @twig.set_property_width_option(property_name => width)
586
- rescue SystemExit => exception
615
+ rescue SystemExit
587
616
  end
588
617
 
589
618
  expect(@twig.options[:property_width]).to eq({})