twig 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,52 +5,103 @@ describe Twig::Options do
5
5
  @twig = Twig.new
6
6
  end
7
7
 
8
- describe '#read_config_file!' do
8
+ describe '#readable_config_file_path' do
9
9
  before :each do
10
- File.should_receive(:expand_path).with(Twig::CONFIG_PATH).
10
+ expect(File).to receive(:expand_path).with(Twig::CONFIG_PATH).
11
11
  and_return(Twig::CONFIG_PATH)
12
12
  end
13
13
 
14
- it 'reads and sets a single option' do
15
- @twig.stub(:all_branch_names => ['test'])
16
- file = double('file')
17
- File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
18
- File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
19
- file.should_receive(:read).and_return('branch: test')
20
- @twig.options[:branch].should be_nil # Precondition
14
+ context 'with a config path that exists' do
15
+ before :each do
16
+ expect(File).to receive(:exists?).with(Twig::CONFIG_PATH).and_return(true)
17
+ end
21
18
 
22
- @twig.read_config_file!
19
+ it 'returns the config path if is readable' do
20
+ path = Twig::CONFIG_PATH
21
+ expect(File).to receive(:readable?).with(path).and_return(true)
22
+ expect($stderr).not_to receive(:puts)
23
+
24
+ result = @twig.readable_config_file_path
23
25
 
24
- @twig.options[:branch].should == 'test'
26
+ expect(result).to eq(path)
27
+ end
28
+
29
+ it 'prints a warning and returns nil if the config path is not readable' do
30
+ path = Twig::CONFIG_PATH
31
+ expect(File).to receive(:readable?).with(path).and_return(false)
32
+ expect($stderr).to receive(:puts) do |message|
33
+ expect(message).to include('not readable')
34
+ end
35
+
36
+ result = @twig.readable_config_file_path
37
+
38
+ expect(result).to be_nil
39
+ end
25
40
  end
26
41
 
27
- it 'reads an option if only the deprecated config file exists' do
28
- @twig.stub(:all_branch_names => ['test'])
29
- file = double('file')
30
- path = Twig::CONFIG_PATH
31
- deprecated_path = Twig::DEPRECATED_CONFIG_PATH
32
- File.should_receive(:readable?).with(path).and_return(false)
33
- File.should_receive(:readable?).with(deprecated_path).and_return(true)
34
- File.should_receive(:expand_path).with(deprecated_path).
35
- and_return(deprecated_path)
36
- File.should_receive(:open).with(deprecated_path).and_yield(file)
37
- file.should_receive(:read).and_return('branch: test')
38
- $stderr.should_receive(:puts) do |message|
39
- message.should =~ /^DEPRECATED:/
42
+ context 'with a config path that does not exist' do
43
+ before :each do
44
+ expect(File).to receive(:exists?).with(Twig::CONFIG_PATH).and_return(false)
45
+ expect(File).to receive(:expand_path).with(Twig::DEPRECATED_CONFIG_PATH).
46
+ and_return(Twig::DEPRECATED_CONFIG_PATH)
40
47
  end
41
- @twig.options[:branch].should be_nil
42
48
 
43
- @twig.read_config_file!
49
+ it 'prints a deprecation warning and returns the deprecated config path if it exists and is readable' do
50
+ path = Twig::DEPRECATED_CONFIG_PATH
51
+ expect(File).to receive(:exists?).with(path).and_return(true)
52
+ expect(File).to receive(:readable?).with(path).and_return(true)
53
+ expect($stderr).to receive(:puts) do |message|
54
+ expect(message).to match(/^DEPRECATED:/)
55
+ expect(message).to include('Please rename')
56
+ expect(message).not_to include('make it readable')
57
+ end
58
+
59
+ result = @twig.readable_config_file_path
44
60
 
45
- @twig.options[:branch].should == 'test'
61
+ expect(result).to eq(path)
62
+ end
63
+
64
+ it 'prints a deprecation warning and returns nil if the deprecated config path exists but is not readable' do
65
+ path = Twig::DEPRECATED_CONFIG_PATH
66
+ expect(File).to receive(:exists?).with(path).and_return(true)
67
+ expect(File).to receive(:readable?).with(path).and_return(false)
68
+ expect($stderr).to receive(:puts) do |message|
69
+ expect(message).to match(/^DEPRECATED:/)
70
+ expect(message).to include('Please rename')
71
+ expect(message).to include('make it readable')
72
+ end
73
+
74
+ result = @twig.readable_config_file_path
75
+
76
+ expect(result).to be_nil
77
+ end
78
+
79
+ it 'returns nil if the deprecated config path does not exist' do
80
+ path = Twig::DEPRECATED_CONFIG_PATH
81
+ expect(File).to receive(:exists?).with(path).and_return(false)
82
+
83
+ result = @twig.readable_config_file_path
84
+
85
+ expect(result).to be_nil
86
+ end
46
87
  end
88
+ end
47
89
 
48
- it 'reads and sets multiple options' do
49
- @twig.stub(:all_branch_names => ['test'])
50
- file = double('file')
51
- File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
52
- File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
53
- file.should_receive(:read).and_return([
90
+ describe '#parse_config_file' do
91
+ before :each do
92
+ @file = double('file')
93
+ @path = Twig::CONFIG_PATH
94
+ expect(File).to receive(:open).with(@path).and_yield(@file)
95
+ end
96
+
97
+ it 'reads a single option' do
98
+ expect(@file).to receive(:read).and_return('branch: test')
99
+ options = @twig.parse_config_file(@path)
100
+ expect(options).to eq('branch' => 'test')
101
+ end
102
+
103
+ it 'reads multiple options' do
104
+ expect(@file).to receive(:read).and_return([
54
105
  # Filtering branches:
55
106
  'branch: test',
56
107
  'max-days-old: 30.5',
@@ -69,258 +120,366 @@ describe Twig::Options do
69
120
  'github-uri-prefix: https://github-enterprise.example.com'
70
121
  ].join("\n"))
71
122
 
72
- # Check preconditions
73
- @twig.options[:branch].should be_nil
74
- @twig.options[:github_api_uri_prefix].should be_nil
75
- @twig.options[:github_uri_prefix].should be_nil
76
- @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
77
- @twig.options[:header_weight].should be_nil
78
- @twig.options[:max_days_old].should be_nil
79
- @twig.options[:property_except].should be_nil
80
- @twig.options[:property_only].should be_nil
81
- @twig.options[:property_width].should be_nil
82
- @twig.options[:reverse].should be_nil
123
+ options = @twig.parse_config_file(@path)
124
+
125
+ expect(options).to eq(
126
+ 'branch' => 'test',
127
+ 'max-days-old' => '30.5',
128
+ 'except-branch' => 'test-except-branch',
129
+ 'only-branch' => 'test-only-branch',
130
+ 'except-foo' => 'test-except-foo',
131
+ 'only-foo' => 'test-only-foo',
132
+ 'header-style' => 'green bold',
133
+ 'reverse' => 'true',
134
+ 'foo-width' => '4',
135
+ 'github-api-uri-prefix' => 'https://github-enterprise.example.com/api/v3',
136
+ 'github-uri-prefix' => 'https://github-enterprise.example.com'
137
+ )
138
+ end
139
+
140
+ it 'skips and reports empty keys' do
141
+ expect(@file).to receive(:read).and_return([
142
+ 'except-branch: foo',
143
+ ': bar'
144
+ ].join("\n"))
145
+ expect($stderr).to receive(:puts) do |message|
146
+ expect(message).to include('Invalid line')
147
+ expect(message).to include(@path)
148
+ end
83
149
 
84
- @twig.read_config_file!
150
+ options = @twig.parse_config_file(@path)
85
151
 
86
- @twig.options[:branch].should == 'test'
87
- @twig.options[:github_api_uri_prefix].
88
- should == 'https://github-enterprise.example.com/api/v3'
89
- @twig.options[:github_uri_prefix].
90
- should == 'https://github-enterprise.example.com'
91
- @twig.options[:header_color].should == :green
92
- @twig.options[:header_weight].should == :bold
93
- @twig.options[:max_days_old].should == 30.5
94
- @twig.options[:property_except].should == {
95
- :branch => /test-except-branch/,
96
- :foo => /test-except-foo/
97
- }
98
- @twig.options[:property_only].should == {
99
- :branch => /test-only-branch/,
100
- :foo => /test-only-foo/
101
- }
102
- @twig.options[:property_width].should == { :foo => 4 }
103
- @twig.options[:reverse].should be_true
152
+ expect(options).to eq('except-branch' => 'foo')
153
+ end
154
+
155
+ it 'skips and reports invalid lines' do
156
+ expect(@file).to receive(:read).and_return([
157
+ 'except-branch: foo',
158
+ 'max-days-old 30'
159
+ ].join("\n"))
160
+ expect($stderr).to receive(:puts) do |message|
161
+ expect(message).to include('Invalid line')
162
+ expect(message).to include(@path)
163
+ end
164
+
165
+ options = @twig.parse_config_file(@path)
166
+
167
+ expect(options).to eq('except-branch' => 'foo')
104
168
  end
105
169
 
106
170
  it 'skips comments' do
107
- file = double('file')
108
- File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
109
- File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
110
- file.should_receive(:read).and_return([
171
+ expect(@file).to receive(:read).and_return([
111
172
  '# max-days-old: 40',
112
173
  'max-days-old: 30',
113
174
  '# max-days-old: 20',
114
175
  ' # foo-width: 4'
115
176
  ].join("\n"))
116
- @twig.options[:max_days_old].should be_nil # Precondition
177
+ expect($stderr).not_to receive(:puts)
117
178
 
118
- @twig.read_config_file!
179
+ options = @twig.parse_config_file(@path)
119
180
 
120
- @twig.options[:max_days_old].should == 30
181
+ expect(options).to eq('max-days-old' => '30')
121
182
  end
122
183
 
123
184
  it 'skips line breaks' do
124
- file = double('file')
125
- File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
126
- File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
127
- file.should_receive(:read).and_return([
185
+ expect(@file).to receive(:read).and_return([
128
186
  'except-branch: test-except',
129
187
  '',
130
188
  'only-branch: test-only'
131
189
  ].join("\n"))
190
+ expect($stderr).not_to receive(:puts)
132
191
 
133
- # Check preconditions
134
- @twig.options[:property_except].should be_nil
135
- @twig.options[:property_only].should be_nil
192
+ options = @twig.parse_config_file(@path)
193
+
194
+ expect(options).to eq(
195
+ 'except-branch' => 'test-except',
196
+ 'only-branch' => 'test-only'
197
+ )
198
+ end
199
+ end
200
+
201
+ describe '#read_config_file!' do
202
+ before :each do
203
+ allow(File).to receive(:expand_path).with(Twig::CONFIG_PATH).
204
+ and_return(Twig::CONFIG_PATH)
205
+ end
206
+
207
+ it 'does nothing if there is no readable config file' do
208
+ allow(@twig).to receive(:readable_config_file_path).and_return(nil)
209
+ expect(@twig).not_to receive(:parse_config_file)
136
210
 
137
211
  @twig.read_config_file!
212
+ end
138
213
 
139
- @twig.options[:property_except].should == { :branch => /test-except/ }
140
- @twig.options[:property_only].should == { :branch => /test-only/ }
214
+ it 'reads and sets a single option' do
215
+ path = Twig::CONFIG_PATH
216
+ allow(@twig).to receive(:all_branch_names) { ['test'] }
217
+ expect(@twig).to receive(:readable_config_file_path).and_return(path)
218
+ expect(@twig).to receive(:parse_config_file).with(path).and_return(
219
+ 'branch' => 'test'
220
+ )
221
+ expect(@twig.options[:branch]).to be_nil
222
+
223
+ @twig.read_config_file!
224
+
225
+ expect(@twig.options[:branch]).to eq('test')
141
226
  end
142
227
 
143
- it 'fails gracefully if the config file is not readable' do
228
+ it 'reads and sets multiple options' do
144
229
  path = Twig::CONFIG_PATH
145
- deprecated_path = Twig::DEPRECATED_CONFIG_PATH
146
- File.should_receive(:readable?).with(path).and_return(false)
147
- File.should_receive(:readable?).with(deprecated_path).and_return(false)
148
- File.should_receive(:expand_path).with(deprecated_path).
149
- and_return(deprecated_path)
150
- lambda { @twig.read_config_file! }.should_not raise_exception
230
+ allow(@twig).to receive(:all_branch_names) { ['test'] }
231
+ expect(@twig).to receive(:readable_config_file_path).and_return(path)
232
+ expect(@twig).to receive(:parse_config_file).with(path).and_return(
233
+ # Filtering branches:
234
+ 'branch' => 'test',
235
+ 'max-days-old' => '30.5',
236
+ 'except-branch' => 'test-except-branch',
237
+ 'only-branch' => 'test-only-branch',
238
+ 'except-foo' => 'test-except-foo',
239
+ 'only-foo' => 'test-only-foo',
240
+
241
+ # Displaying branches:
242
+ 'format' => 'json',
243
+ 'header-style' => 'green bold',
244
+ 'reverse' => 'true',
245
+ 'foo-width' => '4',
246
+
247
+ # GitHub integration:
248
+ 'github-api-uri-prefix' => 'https://github-enterprise.example.com/api/v3',
249
+ 'github-uri-prefix' => 'https://github-enterprise.example.com'
250
+ )
251
+
252
+ # Check preconditions
253
+ expect(@twig.options[:branch]).to be_nil
254
+ expect(@twig.options[:format]).to be_nil
255
+ expect(@twig.options[:github_api_uri_prefix]).to eq(
256
+ Twig::DEFAULT_GITHUB_API_URI_PREFIX
257
+ )
258
+ expect(@twig.options[:github_uri_prefix]).to eq(
259
+ Twig::DEFAULT_GITHUB_URI_PREFIX
260
+ )
261
+ expect(@twig.options[:header_color]).to eq(Twig::DEFAULT_HEADER_COLOR)
262
+ expect(@twig.options[:header_weight]).to be_nil
263
+ expect(@twig.options[:max_days_old]).to be_nil
264
+ expect(@twig.options[:property_except]).to be_nil
265
+ expect(@twig.options[:property_only]).to be_nil
266
+ expect(@twig.options[:property_width]).to be_nil
267
+ expect(@twig.options[:reverse]).to be_nil
268
+
269
+ @twig.read_config_file!
270
+
271
+ expect(@twig.options[:branch]).to eq('test')
272
+ expect(@twig.options[:format]).to eq(:json)
273
+ expect(@twig.options[:github_api_uri_prefix]).to eq(
274
+ 'https://github-enterprise.example.com/api/v3'
275
+ )
276
+ expect(@twig.options[:github_uri_prefix]).to eq(
277
+ 'https://github-enterprise.example.com'
278
+ )
279
+ expect(@twig.options[:header_color]).to eq(:green)
280
+ expect(@twig.options[:header_weight]).to eq(:bold)
281
+ expect(@twig.options[:max_days_old]).to eq(30.5)
282
+ expect(@twig.options[:property_except]).to eq(
283
+ :branch => /test-except-branch/,
284
+ :foo => /test-except-foo/
285
+ )
286
+ expect(@twig.options[:property_only]).to eq(
287
+ :branch => /test-only-branch/,
288
+ :foo => /test-only-foo/
289
+ )
290
+ expect(@twig.options[:property_width]).to eq(:foo => 4)
291
+ expect(@twig.options[:reverse]).to be_true
151
292
  end
152
293
  end
153
294
 
154
295
  describe '#set_option' do
155
296
  context 'when setting a :branch option' do
156
297
  before :each do
157
- @twig.options[:branch].should be_nil # Precondition
298
+ expect(@twig.options[:branch]).to be_nil
158
299
  end
159
300
 
160
301
  it 'succeeds' do
161
302
  branch_name = 'foo'
162
- @twig.should_receive(:all_branch_names).and_return(%[foo bar])
303
+ expect(@twig).to receive(:all_branch_names).and_return(%[foo bar])
163
304
 
164
305
  @twig.set_option(:branch, branch_name)
165
306
 
166
- @twig.options[:branch].should == branch_name
307
+ expect(@twig.options[:branch]).to eq(branch_name)
167
308
  end
168
309
 
169
310
  it 'fails if the branch is unknown' do
170
311
  branch_name = 'foo'
171
- @twig.should_receive(:all_branch_names).and_return([])
172
- @twig.should_receive(:abort) do |message|
173
- message.should include(%{branch "#{branch_name}" could not be found})
312
+ expect(@twig).to receive(:all_branch_names).and_return([])
313
+ expect(@twig).to receive(:abort) do |message|
314
+ expect(message).to include(%{branch `#{branch_name}` could not be found})
174
315
  end
175
316
 
176
317
  @twig.set_option(:branch, branch_name)
177
318
 
178
- @twig.options[:branch].should be_nil
319
+ expect(@twig.options[:branch]).to be_nil
320
+ end
321
+ end
322
+
323
+ context 'when setting a :format option' do
324
+ it 'succeeds' do
325
+ @twig.set_option(:format, 'json')
326
+ expect(@twig.options[:format]).to eq(:json)
327
+ end
328
+
329
+ it 'fails if the option is not :json' do
330
+ value = 'foo'
331
+ expect(@twig).to receive(:abort) do |message|
332
+ expect(message).to include("format `#{value}` is not supported")
333
+ end
334
+
335
+ @twig.set_option(:format, value)
336
+
337
+ expect(@twig.options[:format]).to be_nil
179
338
  end
180
339
  end
181
340
 
182
341
  it 'sets a :github_api_uri_prefix option' do
183
342
  prefix = 'https://github-enterprise.example.com/api/v3'
184
343
  @twig.set_option(:github_api_uri_prefix, prefix)
185
- @twig.options[:github_api_uri_prefix].should == prefix
344
+ expect(@twig.options[:github_api_uri_prefix]).to eq(prefix)
186
345
  end
187
346
 
188
347
  it 'sets a :github_uri_prefix option' do
189
348
  prefix = 'https://github-enterprise.example.com'
190
349
  @twig.set_option(:github_uri_prefix, prefix)
191
- @twig.options[:github_uri_prefix].should == prefix
350
+ expect(@twig.options[:github_uri_prefix]).to eq(prefix)
192
351
  end
193
352
 
194
353
  it 'sets a :header_style option' do
195
354
  style = 'red bold'
196
- @twig.should_receive(:set_header_style_option).with(style)
355
+ expect(@twig).to receive(:set_header_style_option).with(style)
197
356
 
198
357
  @twig.set_option(:header_style, style)
199
358
  end
200
359
 
201
360
  context 'when setting a :max_days_old option' do
202
361
  before :each do
203
- @twig.options[:max_days_old].should be_nil # Precondition
362
+ expect(@twig.options[:max_days_old]).to be_nil
204
363
  end
205
364
 
206
365
  it 'succeeds' do
207
366
  @twig.set_option(:max_days_old, 1)
208
- @twig.options[:max_days_old].should == 1
367
+ expect(@twig.options[:max_days_old]).to eq(1)
209
368
  end
210
369
 
211
370
  it 'fails if the option is not numeric' do
212
371
  value = 'blargh'
213
- @twig.should_receive(:abort) do |message|
214
- message.should include("`--max-days-old=#{value}` is invalid")
372
+ expect(@twig).to receive(:abort) do |message|
373
+ expect(message).to include("`--max-days-old=#{value}` is invalid")
215
374
  end
216
375
  @twig.set_option(:max_days_old, value)
217
376
 
218
- @twig.options[:max_days_old].should be_nil
377
+ expect(@twig.options[:max_days_old]).to be_nil
219
378
  end
220
379
  end
221
380
 
222
381
  it 'sets a :property_except option' do
223
- @twig.options[:property_except].should be_nil # Precondition
382
+ expect(@twig.options[:property_except]).to be_nil
224
383
  @twig.set_option(:property_except, :branch => 'unwanted_prefix_')
225
- @twig.options[:property_except].should == { :branch => /unwanted_prefix_/ }
384
+ expect(@twig.options[:property_except]).to eq(:branch => /unwanted_prefix_/)
226
385
  end
227
386
 
228
387
  it 'sets a :property_only option' do
229
- @twig.options[:property_only].should be_nil # Precondition
388
+ expect(@twig.options[:property_only]).to be_nil
230
389
  @twig.set_option(:property_only, :branch => 'important_prefix_')
231
- @twig.options[:property_only].should == { :branch => /important_prefix_/ }
390
+ expect(@twig.options[:property_only]).to eq(:branch => /important_prefix_/)
232
391
  end
233
392
 
234
393
  it 'sets a :property_width option' do
235
394
  width = 10
236
- @twig.should_receive(:set_property_width_option).with(width)
395
+ expect(@twig).to receive(:set_property_width_option).with(width)
237
396
 
238
397
  @twig.set_option(:property_width, width)
239
398
  end
240
399
 
241
400
  context 'when setting a :reverse option' do
242
401
  before :each do
243
- @twig.options[:reverse].should be_nil # Precondition
402
+ expect(@twig.options[:reverse]).to be_nil
244
403
  end
245
404
 
246
405
  it 'sets the option to true when input is truthy' do
247
406
  input = 'yes'
248
- Twig::Util.should_receive(:truthy?).with(input).and_call_original
407
+ expect(Twig::Util).to receive(:truthy?).with(input).and_call_original
249
408
 
250
409
  @twig.set_option(:reverse, input)
251
410
 
252
- @twig.options[:reverse].should be_true
411
+ expect(@twig.options[:reverse]).to be_true
253
412
  end
254
413
 
255
414
  it 'sets the option to false when input is not truthy' do
256
415
  input = 'blargh'
257
- Twig::Util.should_receive(:truthy?).with(input).and_call_original
416
+ expect(Twig::Util).to receive(:truthy?).with(input).and_call_original
258
417
 
259
418
  @twig.set_option(:reverse, input)
260
419
 
261
- @twig.options[:reverse].should be_false
420
+ expect(@twig.options[:reverse]).to be_false
262
421
  end
263
422
  end
264
423
 
265
424
  it 'sets an :unset_property option' do
266
- @twig.options[:unset_property].should be_nil # Precondition
425
+ expect(@twig.options[:unset_property]).to be_nil
267
426
  @twig.set_option(:unset_property, 'unwanted_property')
268
- @twig.options[:unset_property].should == 'unwanted_property'
427
+ expect(@twig.options[:unset_property]).to eq('unwanted_property')
269
428
  end
270
429
  end
271
430
 
272
431
  describe '#set_header_style_option' do
273
432
  before :each do
274
433
  # Preconditions:
275
- @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
276
- @twig.options[:header_weight].should be_nil
434
+ expect(@twig.options[:header_color]).to eq(Twig::DEFAULT_HEADER_COLOR)
435
+ expect(@twig.options[:header_weight]).to be_nil
277
436
  end
278
437
 
279
438
  it 'succeeds at setting a color option' do
280
439
  @twig.set_header_style_option('red')
281
- @twig.options[:header_color].should == :red
282
- @twig.options[:header_weight].should be_nil
440
+ expect(@twig.options[:header_color]).to eq(:red)
441
+ expect(@twig.options[:header_weight]).to be_nil
283
442
  end
284
443
 
285
444
  it 'succeeds at setting a weight option' do
286
445
  @twig.set_header_style_option('bold')
287
- @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
288
- @twig.options[:header_weight].should == :bold
446
+ expect(@twig.options[:header_color]).to eq(Twig::DEFAULT_HEADER_COLOR)
447
+ expect(@twig.options[:header_weight]).to eq(:bold)
289
448
  end
290
449
 
291
450
  it 'succeeds at setting color and weight options, color first' do
292
451
  @twig.set_header_style_option('red bold')
293
- @twig.options[:header_color].should == :red
294
- @twig.options[:header_weight].should == :bold
452
+ expect(@twig.options[:header_color]).to eq(:red)
453
+ expect(@twig.options[:header_weight]).to eq(:bold)
295
454
  end
296
455
 
297
456
  it 'succeeds at setting color and weight options, weight first' do
298
457
  @twig.set_header_style_option('bold red')
299
- @twig.options[:header_color].should == :red
300
- @twig.options[:header_weight].should == :bold
458
+ expect(@twig.options[:header_color]).to eq(:red)
459
+ expect(@twig.options[:header_weight]).to eq(:bold)
301
460
  end
302
461
 
303
462
  it 'succeeds at setting color and weight options with extra space between words' do
304
463
  @twig.set_header_style_option('red bold')
305
- @twig.options[:header_color].should == :red
306
- @twig.options[:header_weight].should == :bold
464
+ expect(@twig.options[:header_color]).to eq(:red)
465
+ expect(@twig.options[:header_weight]).to eq(:bold)
307
466
  end
308
467
 
309
468
  it 'fails if the one-word option is invalid' do
310
469
  style = 'handsofblue' # Two by two...
311
- @twig.should_receive(:abort) do |message|
312
- message.should include("`--header-style=#{style}` is invalid")
470
+ expect(@twig).to receive(:abort) do |message|
471
+ expect(message).to include("`--header-style=#{style}` is invalid")
313
472
  end
314
473
  @twig.set_header_style_option(style)
315
474
 
316
- @twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
317
- @twig.options[:header_weight].should be_nil
475
+ expect(@twig.options[:header_color]).to eq(Twig::DEFAULT_HEADER_COLOR)
476
+ expect(@twig.options[:header_weight]).to be_nil
318
477
  end
319
478
 
320
479
  it 'fails if the color of the two-word option is invalid' do
321
480
  style = 'handsofblue bold'
322
- @twig.should_receive(:abort) do |message|
323
- message.should include("`--header-style=#{style}` is invalid")
481
+ expect(@twig).to receive(:abort) do |message|
482
+ expect(message).to include("`--header-style=#{style}` is invalid")
324
483
  end
325
484
 
326
485
  @twig.set_header_style_option(style)
@@ -328,8 +487,8 @@ describe Twig::Options do
328
487
 
329
488
  it 'fails if the weight of the two-word option is invalid' do
330
489
  style = 'red extrabold'
331
- @twig.should_receive(:abort) do |message|
332
- message.should include("`--header-style=#{style}` is invalid")
490
+ expect(@twig).to receive(:abort) do |message|
491
+ expect(message).to include("`--header-style=#{style}` is invalid")
333
492
  end
334
493
 
335
494
  @twig.set_header_style_option(style)
@@ -337,8 +496,8 @@ describe Twig::Options do
337
496
 
338
497
  it 'fails if there are two colors' do
339
498
  style = 'red green'
340
- @twig.should_receive(:abort) do |message|
341
- message.should include("`--header-style=#{style}` is invalid")
499
+ expect(@twig).to receive(:abort) do |message|
500
+ expect(message).to include("`--header-style=#{style}` is invalid")
342
501
  end
343
502
 
344
503
  @twig.set_header_style_option(style)
@@ -346,8 +505,8 @@ describe Twig::Options do
346
505
 
347
506
  it 'fails if there are two weights' do
348
507
  style = 'bold bold'
349
- @twig.should_receive(:abort) do |message|
350
- message.should include("`--header-style=#{style}` is invalid")
508
+ expect(@twig).to receive(:abort) do |message|
509
+ expect(message).to include("`--header-style=#{style}` is invalid")
351
510
  end
352
511
 
353
512
  @twig.set_header_style_option(style)
@@ -356,18 +515,18 @@ describe Twig::Options do
356
515
 
357
516
  describe '#set_property_width_option' do
358
517
  before :each do
359
- @twig.options[:property_width].should be_nil # Precondition
518
+ expect(@twig.options[:property_width]).to be_nil
360
519
  end
361
520
 
362
521
  it 'succeeds' do
363
522
  @twig.set_option(:property_width, :foo => '20', :bar => '40')
364
- @twig.options[:property_width].should == { :foo => 20, :bar => 40 }
523
+ expect(@twig.options[:property_width]).to eq(:foo => 20, :bar => 40)
365
524
  end
366
525
 
367
526
  it 'fails if width is not numeric' do
368
527
  width = 'blargh'
369
- @twig.should_receive(:abort) do |message|
370
- message.should include("`--branch-width=#{width}` is invalid")
528
+ expect(@twig).to receive(:abort) do |message|
529
+ expect(message).to include("`--branch-width=#{width}` is invalid")
371
530
  abort # Original behavior, but don't show message in test output
372
531
  end
373
532
 
@@ -376,15 +535,15 @@ describe Twig::Options do
376
535
  rescue SystemExit => exception
377
536
  end
378
537
 
379
- @twig.options[:property_width].should be_nil
538
+ expect(@twig.options[:property_width]).to be_nil
380
539
  end
381
540
 
382
541
  it 'fails if width is below minimum value' do
383
542
  min_width = Twig::Options::MIN_PROPERTY_WIDTH
384
543
  width = min_width - 1
385
- @twig.should_receive(:abort) do |message|
386
- message.should include("`--x-width=#{width}` is too low. ")
387
- message.should include("The minimum is #{min_width}.")
544
+ expect(@twig).to receive(:abort) do |message|
545
+ expect(message).to include("`--x-width=#{width}` is too low. ")
546
+ expect(message).to include("The minimum is #{min_width}.")
388
547
  abort
389
548
  end
390
549
 
@@ -393,15 +552,15 @@ describe Twig::Options do
393
552
  rescue SystemExit => exception
394
553
  end
395
554
 
396
- @twig.options[:property_width].should be_nil
555
+ expect(@twig.options[:property_width]).to be_nil
397
556
  end
398
557
 
399
558
  it 'fails if width is below width of property name' do
400
559
  property_name = :foobarbaz
401
560
  width = property_name.to_s.size - 1
402
- @twig.should_receive(:abort) do |message|
403
- message.should include("`--#{property_name}-width=#{width}` is too low. ")
404
- message.should include(%{The minimum is 9 (width of "#{property_name}")})
561
+ expect(@twig).to receive(:abort) do |message|
562
+ expect(message).to include("`--#{property_name}-width=#{width}` is too low. ")
563
+ expect(message).to include(%{The minimum is 9 (width of "#{property_name}")})
405
564
  abort
406
565
  end
407
566
 
@@ -410,17 +569,17 @@ describe Twig::Options do
410
569
  rescue SystemExit => exception
411
570
  end
412
571
 
413
- @twig.options[:property_width].should be_nil
572
+ expect(@twig.options[:property_width]).to be_nil
414
573
  end
415
574
  end
416
575
 
417
576
  describe '#unset_option' do
418
577
  it 'unsets an option' do
419
578
  @twig.set_option(:max_days_old, 1)
420
- @twig.options[:max_days_old].should == 1 # Precondition
579
+ expect(@twig.options[:max_days_old]).to eq(1)
421
580
 
422
581
  @twig.unset_option(:max_days_old)
423
- @twig.options[:max_days_old].should be_nil
582
+ expect(@twig.options[:max_days_old]).to be_nil
424
583
  end
425
584
  end
426
585
  end