icu_tournament 1.9.3 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,15 +6,15 @@ module ICU
6
6
  describe ForeignCSV do
7
7
  def check_player(num, first, last, results, rateable, points, other={})
8
8
  p = @t.player(num)
9
- p.first_name.should == first
10
- p.last_name.should == last
11
- p.id.should == other[:id]
12
- p.fide_rating.should == other[:fide_rating]
13
- p.fed.should == other[:fed]
14
- p.title.should == other[:title]
15
- p.results.size.should == results
16
- p.results.select{|r| r.rateable}.size.should == rateable
17
- p.points.should == points
9
+ expect(p.first_name).to eq(first)
10
+ expect(p.last_name).to eq(last)
11
+ expect(p.id).to eq(other[:id])
12
+ expect(p.fide_rating).to eq(other[:fide_rating])
13
+ expect(p.fed).to eq(other[:fed])
14
+ expect(p.title).to eq(other[:title])
15
+ expect(p.results.size).to eq(results)
16
+ expect(p.results.select{|r| r.rateable}.size).to eq(rateable)
17
+ expect(p.points).to eq(points)
18
18
  end
19
19
 
20
20
  context "a typical tournament" do
@@ -38,23 +38,23 @@ CSV
38
38
  end
39
39
 
40
40
  it "should have a name" do
41
- @t.name.should == 'Bangor Open, 2003'
41
+ expect(@t.name).to eq('Bangor Open, 2003')
42
42
  end
43
43
 
44
44
  it "should have a start date" do
45
- @t.start.should == '2003-07-01'
45
+ expect(@t.start).to eq('2003-07-01')
46
46
  end
47
47
 
48
48
  it "should have a number of rounds" do
49
- @t.rounds.should == 4
49
+ expect(@t.rounds).to eq(4)
50
50
  end
51
51
 
52
52
  it "should have a website" do
53
- @t.site.should == 'http://www.icu.ie/tournaments/display.php?id=371'
53
+ expect(@t.site).to eq('http://www.icu.ie/tournaments/display.php?id=371')
54
54
  end
55
55
 
56
56
  it "should have some players" do
57
- @t.should have(4).players
57
+ expect(@t.players.size).to eq(4)
58
58
  end
59
59
 
60
60
  it "should have correct player details" do
@@ -65,7 +65,7 @@ CSV
65
65
  end
66
66
 
67
67
  it "should be valid" do
68
- @t.invalid.should be_false
68
+ expect(@t.invalid).to be_falsey
69
69
  end
70
70
  end
71
71
 
@@ -98,29 +98,29 @@ CSV
98
98
  end
99
99
 
100
100
  it "should have correct basic details" do
101
- @t.name.should == 'Isle of Man Masters, 2007'
102
- @t.start.should == '2007-09-22'
103
- @t.rounds.should == 9
104
- @t.site.should == 'http://www.bcmchess.co.uk/monarch2007/'
101
+ expect(@t.name).to eq('Isle of Man Masters, 2007')
102
+ expect(@t.start).to eq('2007-09-22')
103
+ expect(@t.rounds).to eq(9)
104
+ expect(@t.site).to eq('http://www.bcmchess.co.uk/monarch2007/')
105
105
  end
106
106
 
107
107
  it "should have the right number of players in the right order" do
108
- @t.players.size.should == 9
109
- @t.players.inject(''){ |a,o| a << o.num.to_s }.should == '123456789'
108
+ expect(@t.players.size).to eq(9)
109
+ expect(@t.players.inject(''){ |a,o| a << o.num.to_s }).to eq('123456789')
110
110
  end
111
111
 
112
112
  it "should have the right details for the main player" do
113
- @p.name.should == "Fox, Anthony"
113
+ expect(@p.name).to eq("Fox, Anthony")
114
114
  @p.results.size == 9
115
- @p.results.find_all{ |r| r.rateable }.size.should == 8
116
- @p.points.should == 4.0
115
+ expect(@p.results.find_all{ |r| r.rateable }.size).to eq(8)
116
+ expect(@p.points).to eq(4.0)
117
117
  end
118
118
 
119
119
  it "should have the right details for the opponents" do
120
- @o.size.should == 8
121
- @o.find_all{ |o| o.results.size == 1}.size.should == 8
122
- @r.name.should == "Taylor, Peter P."
123
- @r.results[0].rateable.should be_true
120
+ expect(@o.size).to eq(8)
121
+ expect(@o.find_all{ |o| o.results.size == 1}.size).to eq(8)
122
+ expect(@r.name).to eq("Taylor, Peter P.")
123
+ expect(@r.results[0].rateable).to be_truthy
124
124
  end
125
125
  end
126
126
 
@@ -148,14 +148,14 @@ CSV
148
148
  end
149
149
 
150
150
  it "should have the usual basic details" do
151
- @t.name.should == 'Edinburgh Masters, 2007'
152
- @t.start.should == '2007-01-03'
153
- @t.rounds.should == 2
154
- @t.site.should == 'http://www.chesscenter.com/twic/twic.html'
151
+ expect(@t.name).to eq('Edinburgh Masters, 2007')
152
+ expect(@t.start).to eq('2007-01-03')
153
+ expect(@t.rounds).to eq(2)
154
+ expect(@t.site).to eq('http://www.chesscenter.com/twic/twic.html')
155
155
  end
156
156
 
157
157
  it "should have the correct number of players" do
158
- @t.should have(5).players
158
+ expect(@t.players.size).to eq(5)
159
159
  end
160
160
 
161
161
  it "should have correct player details" do
@@ -191,14 +191,14 @@ CSV
191
191
  end
192
192
 
193
193
  it "should have the usual basic details" do
194
- @t.name.should == 'Bratto Open, 2001'
195
- @t.start.should == '2001-03-07'
196
- @t.rounds.should == 2
197
- @t.site.should == 'http://www.federscacchi.it/'
194
+ expect(@t.name).to eq('Bratto Open, 2001')
195
+ expect(@t.start).to eq('2001-03-07')
196
+ expect(@t.rounds).to eq(2)
197
+ expect(@t.site).to eq('http://www.federscacchi.it/')
198
198
  end
199
199
 
200
200
  it "should have the correct number of players" do
201
- @t.should have(4).players
201
+ expect(@t.players.size).to eq(4)
202
202
  end
203
203
 
204
204
  it "should have correct player details" do
@@ -231,14 +231,14 @@ CSV
231
231
  end
232
232
 
233
233
  it "should have the correct basic details" do
234
- @t.name.should == 'Bratto Open, 2001'
235
- @t.start.should == '2001-03-07'
236
- @t.rounds.should == 2
237
- @t.site.should == 'http://www.federscacchi.it/'
234
+ expect(@t.name).to eq('Bratto Open, 2001')
235
+ expect(@t.start).to eq('2001-03-07')
236
+ expect(@t.rounds).to eq(2)
237
+ expect(@t.site).to eq('http://www.federscacchi.it/')
238
238
  end
239
239
 
240
240
  it "should have the correct number of players" do
241
- @t.should have(3).players
241
+ expect(@t.players.size).to eq(3)
242
242
  end
243
243
 
244
244
  it "should have correct player details" do
@@ -248,9 +248,9 @@ CSV
248
248
  end
249
249
 
250
250
  it "should still have original names" do
251
- @t.player(1).original_name.should == "ui Laighleis, gearoidin"
252
- @t.player(2).original_name.should == "kasparov, gary"
253
- @t.player(3).original_name.should == "Orr, Mark"
251
+ expect(@t.player(1).original_name).to eq("ui Laighleis, gearoidin")
252
+ expect(@t.player(2).original_name).to eq("kasparov, gary")
253
+ expect(@t.player(3).original_name).to eq("Orr, Mark")
254
254
  end
255
255
  end
256
256
 
@@ -272,13 +272,13 @@ Player,3364,Ui Laighleis,Gearoidin
272
272
  2,=,B,Orr,Mark,2100,IM,IRL
273
273
  Total,1.0
274
274
  CSV
275
- @f.parse(csv).should be_an_instance_of(ICU::Tournament)
276
- @f.error.should be_nil
275
+ expect(@f.parse(csv)).to be_an_instance_of(ICU::Tournament)
276
+ expect(@f.error).to be_nil
277
277
  end
278
278
 
279
279
  it "should not throw an exception but return nil on error" do
280
- @f.parse(' ').should be_nil
281
- @f.error.should match(/event/)
280
+ expect(@f.parse(' ')).to be_nil
281
+ expect(@f.error).to match(/event/)
282
282
  end
283
283
  end
284
284
 
@@ -288,7 +288,7 @@ CSV
288
288
  end
289
289
 
290
290
  it "a blank file is invalid" do
291
- lambda { @f.parse!(' ') }.should raise_error(/event/i)
291
+ expect { @f.parse!(' ') }.to raise_error(/event/i)
292
292
  end
293
293
 
294
294
  it "the event should come first" do
@@ -299,7 +299,7 @@ Event,"Bratto Open, 2001"
299
299
  Rounds,2
300
300
  Website,http://www.federscacchi.it/
301
301
  CSV
302
- lambda { @f.parse!(csv) }.should raise_error(/line 1.*event/i)
302
+ expect { @f.parse!(csv) }.to raise_error(/line 1.*event/i)
303
303
  end
304
304
 
305
305
  it "the start should come next" do
@@ -310,7 +310,7 @@ Rounds,2
310
310
  Start,7th March 2001
311
311
  Website,http://www.federscacchi.it/
312
312
  CSV
313
- lambda { @f.parse!(csv) }.should raise_error(/line 2.*start/i)
313
+ expect { @f.parse!(csv) }.to raise_error(/line 2.*start/i)
314
314
  end
315
315
 
316
316
  it "the end should come next" do
@@ -321,7 +321,7 @@ Rounds,2
321
321
  Start,7th March 2001
322
322
  Website,http://www.federscacchi.it/
323
323
  CSV
324
- lambda { @f.parse!(csv) }.should raise_error(/line 3.*end/i)
324
+ expect { @f.parse!(csv) }.to raise_error(/line 3.*end/i)
325
325
  end
326
326
 
327
327
  it "the number of rounds should come next" do
@@ -332,7 +332,7 @@ End,7th March 2001
332
332
  Website,http://www.federscacchi.it/
333
333
  Rounds,2
334
334
  CSV
335
- lambda { @f.parse!(csv) }.should raise_error(/line 4.*rounds/i)
335
+ expect { @f.parse!(csv) }.to raise_error(/line 4.*rounds/i)
336
336
  end
337
337
 
338
338
  it "there should be a web site" do
@@ -343,7 +343,7 @@ End,7th March 2001
343
343
  Rounds,2
344
344
 
345
345
  CSV
346
- lambda { @f.parse!(csv) }.should raise_error(/line 5.*site/i)
346
+ expect { @f.parse!(csv) }.to raise_error(/line 5.*site/i)
347
347
  end
348
348
 
349
349
  it "should have at least one player" do
@@ -355,7 +355,7 @@ Rounds,2
355
355
  Website,http://www.federscacchi.it/
356
356
 
357
357
  CSV
358
- lambda { @f.parse!(csv) }.should raise_error(/line 6.*no players/i)
358
+ expect { @f.parse!(csv) }.to raise_error(/line 6.*no players/i)
359
359
  end
360
360
 
361
361
  it "the player needs to have a valid ID number" do
@@ -368,7 +368,7 @@ Website,http://www.federscacchi.it/
368
368
 
369
369
  Player,0,Ui Laighleis,Gearoidin
370
370
  CSV
371
- lambda { @f.parse!(csv) }.should raise_error(/line 7.*number/i)
371
+ expect { @f.parse!(csv) }.to raise_error(/line 7.*number/i)
372
372
  end
373
373
 
374
374
  it "should have the right number of results for each player" do
@@ -383,7 +383,7 @@ Player,3364,Ui Laighleis,Gearoidin
383
383
  1,=,W,Kasparov,Gary,2800,GM,RUS
384
384
  Total,0.5
385
385
  CSV
386
- lambda { @f.parse!(csv) }.should raise_error(/line 9.*round/i)
386
+ expect { @f.parse!(csv) }.to raise_error(/line 9.*round/i)
387
387
  end
388
388
 
389
389
  it "should have correct totals" do
@@ -399,7 +399,7 @@ Player,3364,Ui Laighleis,Gearoidin
399
399
  2,=,B,Orr,Mark,2100,IM,IRL
400
400
  Total,1.5
401
401
  CSV
402
- lambda { @f.parse!(csv) }.should raise_error(/line 10.*total/i)
402
+ expect { @f.parse!(csv) }.to raise_error(/line 10.*total/i)
403
403
  end
404
404
 
405
405
  it "players who match by name and federation should match in all other details" do
@@ -420,7 +420,7 @@ Player,1350,Orr,Mark
420
420
  2,=,B,Kasparov,Gary,2850,GM,RUS
421
421
  Total,1.0
422
422
  CSV
423
- lambda { @f.parse!(csv) }.should raise_error(/line 14.*same name.*conflicting/i)
423
+ expect { @f.parse!(csv) }.to raise_error(/line 14.*same name.*conflicting/i)
424
424
  end
425
425
  end
426
426
 
@@ -448,7 +448,7 @@ CSV
448
448
  end
449
449
 
450
450
  it "should serialize back to the original" do
451
- @f.serialize(@t).should == @csv
451
+ expect(@f.serialize(@t)).to eq(@csv)
452
452
  end
453
453
  end
454
454
 
@@ -527,7 +527,7 @@ CSV
527
527
  end
528
528
 
529
529
  it "should serialize to the expected string" do
530
- @t.serialize('ForeignCSV').should == @csv
530
+ expect(@t.serialize('ForeignCSV')).to eq(@csv)
531
531
  end
532
532
  end
533
533
 
@@ -577,7 +577,7 @@ CSV
577
577
  end
578
578
 
579
579
  it "should serialize to the expected string" do
580
- @t.serialize('ForeignCSV').should == @csv
580
+ expect(@t.serialize('ForeignCSV')).to eq(@csv)
581
581
  end
582
582
  end
583
583
 
@@ -599,20 +599,20 @@ CSV
599
599
  end
600
600
 
601
601
  it "should parse UTF-8" do
602
- lambda { @t = @f.parse!(@csv) }.should_not raise_error
602
+ expect { @t = @f.parse!(@csv) }.not_to raise_error
603
603
  check_player(1, 'Gearoìdin', 'Uì Laighlèis', 2, 2, 1.0, :id => 3364)
604
604
  check_player(2, 'Gary', 'Kasparov', 1, 1, 0.5, :fide_rating => 2800, :fed => 'RUS', :title => 'GM')
605
605
  check_player(3, 'Mârk', 'Örr', 1, 1, 0.5, :fide_rating => 2100, :fed => 'IRL', :title => 'IM')
606
- @t.name.should == "Brätto Open, 2001"
606
+ expect(@t.name).to eq("Brätto Open, 2001")
607
607
  end
608
608
 
609
609
  it "should parse Latin-1" do
610
610
  @csv = @csv.encode("ISO-8859-1")
611
- lambda { @t = @f.parse!(@csv) }.should_not raise_error
611
+ expect { @t = @f.parse!(@csv) }.not_to raise_error
612
612
  check_player(1, 'Gearoìdin', 'Uì Laighlèis', 2, 2, 1.0, :id => 3364)
613
613
  check_player(2, 'Gary', 'Kasparov', 1, 1, 0.5, :fide_rating => 2800, :fed => 'RUS', :title => 'GM')
614
614
  check_player(3, 'Mârk', 'Örr', 1, 1, 0.5, :fide_rating => 2100, :fed => 'IRL', :title => 'IM')
615
- @t.name.should == "Brätto Open, 2001"
615
+ expect(@t.name).to eq("Brätto Open, 2001")
616
616
  end
617
617
  end
618
618
 
@@ -624,49 +624,49 @@ CSV
624
624
 
625
625
  it "should error on a non-existant valid file" do
626
626
  file = "#{@s}/not_there.csv"
627
- lambda { @p.parse_file!(file) }.should raise_error
627
+ expect { @p.parse_file!(file) }.to raise_error
628
628
  t = @p.parse_file(file)
629
- t.should be_nil
630
- @p.error.should match(/no such file/i)
629
+ expect(t).to be_nil
630
+ expect(@p.error).to match(/no such file/i)
631
631
  end
632
632
 
633
633
  it "should error on an invalid file" do
634
634
  file = "#{@s}/invalid.csv"
635
- lambda { @p.parse_file!(file) }.should raise_error
635
+ expect { @p.parse_file!(file) }.to raise_error
636
636
  t = @p.parse_file(file)
637
- t.should be_nil
638
- @p.error.should match(/expected.*event.*name/i)
637
+ expect(t).to be_nil
638
+ expect(@p.error).to match(/expected.*event.*name/i)
639
639
  end
640
640
 
641
641
  it "should parse a valid file" do
642
642
  file = "#{@s}/valid.csv"
643
- lambda { @p.parse_file!(file) }.should_not raise_error
643
+ expect { @p.parse_file!(file) }.not_to raise_error
644
644
  t = @p.parse_file(file)
645
- t.should be_an_instance_of(ICU::Tournament)
646
- t.players.size.should == 16
645
+ expect(t).to be_an_instance_of(ICU::Tournament)
646
+ expect(t.players.size).to eq(16)
647
647
  end
648
648
 
649
649
  it "should parse a file encoded in UTF-8" do
650
650
  file = "#{@s}/utf-8.csv"
651
- lambda { @t = @p.parse_file!(file) }.should_not raise_error
651
+ expect { @t = @p.parse_file!(file) }.not_to raise_error
652
652
  check_player(1, 'Gearoìdin', 'Uì Laighlèis', 2, 2, 1.0, :id => 3364)
653
653
  check_player(2, 'Gary', 'Kasparov', 1, 1, 0.5, :fide_rating => 2800, :fed => 'RUS', :title => 'GM')
654
654
  check_player(3, 'Mârk', 'Örr', 1, 1, 0.5, :fide_rating => 2100, :fed => 'IRL', :title => 'IM')
655
- @t.name.should == "Brätto Open, 2001"
655
+ expect(@t.name).to eq("Brätto Open, 2001")
656
656
  end
657
657
 
658
658
  it "should parse a file encoded in Latin-1" do
659
659
  file = "#{@s}/latin-1.csv"
660
- lambda { @t = @p.parse_file!(file) }.should_not raise_error
660
+ expect { @t = @p.parse_file!(file) }.not_to raise_error
661
661
  check_player(1, 'Gearoìdin', 'Uì Laighlèis', 2, 2, 1.0, :id => 3364)
662
662
  check_player(2, 'Gary', 'Kasparov', 1, 1, 0.5, :fide_rating => 2800, :fed => 'RUS', :title => 'GM')
663
663
  check_player(3, 'Mârk', 'Örr', 1, 1, 0.5, :fide_rating => 2100, :fed => 'IRL', :title => 'IM')
664
- @t.name.should == "Brätto Open, 2001"
664
+ expect(@t.name).to eq("Brätto Open, 2001")
665
665
  end
666
666
 
667
667
  it "should parse this practical example" do
668
668
  file = "#{@s}/4ncl.csv"
669
- lambda { @t = @p.parse_file!(file) }.should_not raise_error
669
+ expect { @t = @p.parse_file!(file) }.not_to raise_error
670
670
  check_player(1, 'Ryan-Rhys', 'Griffiths', 3, 3, 1.5, :id => 6897)
671
671
  end
672
672
  end
@@ -690,31 +690,31 @@ CSV
690
690
  end
691
691
 
692
692
  it "should pass" do
693
- @t.invalid.should be_false
694
- @t.invalid(:type => @p).should be_false
693
+ expect(@t.invalid).to be_falsey
694
+ expect(@t.invalid(:type => @p)).to be_falsey
695
695
  end
696
696
 
697
697
  it "should fail if there's no site" do
698
698
  @t.site = nil;
699
- @t.invalid(:type => @p).to_s.should match(/site/)
699
+ expect(@t.invalid(:type => @p).to_s).to match(/site/)
700
700
  end
701
701
 
702
702
  it "should fail if there are no ICU players" do
703
703
  [1, 2].each { |n| @t.player(n).id = nil }
704
704
  @t.player(2).id = nil;
705
- @t.invalid(:type => @p).to_s.should match(/ID/)
705
+ expect(@t.invalid(:type => @p).to_s).to match(/ID/)
706
706
  end
707
707
 
708
708
  it "should fail unless all foreign players have a federation" do
709
709
  @t.player(10).fed = nil;
710
- @t.invalid(:type => @p).to_s.should match(/federation/)
710
+ expect(@t.invalid(:type => @p).to_s).to match(/federation/)
711
711
  end
712
712
 
713
713
  it "should fail unless at least one ICU player has a result in every round" do
714
714
  @t.add_result(ICU::Result.new(3, 10, 'W', :opponent => 30, :colour => 'W'))
715
- @t.invalid(:type => @p).to_s.should match(/at least one.*result.*every/)
715
+ expect(@t.invalid(:type => @p).to_s).to match(/at least one.*result.*every/)
716
716
  @t.add_result(ICU::Result.new(3, 1, 'W', :opponent => 20, :colour => 'W'))
717
- @t.invalid(:type => @p).should be_false
717
+ expect(@t.invalid(:type => @p)).to be_falsey
718
718
  end
719
719
 
720
720
  it "should fail unless every ICU player's opponents have a federation" do
@@ -723,17 +723,17 @@ CSV
723
723
  @t.add_result(ICU::Result.new(2, 3, 'W', :opponent => 10, :colour => 'W'))
724
724
  @t.add_result(ICU::Result.new(3, 1, 'D', :opponent => 40, :colour => 'W'))
725
725
  @t.add_result(ICU::Result.new(3, 2, 'L', :opponent => 3, :colour => 'B'))
726
- @t.invalid(:type => @p).to_s.should match(/opponents.*federation/)
726
+ expect(@t.invalid(:type => @p).to_s).to match(/opponents.*federation/)
727
727
  @t.player(2).fed = 'IRL'
728
- @t.invalid(:type => @p).to_s.should match(/opponents.*federation/)
728
+ expect(@t.invalid(:type => @p).to_s).to match(/opponents.*federation/)
729
729
  @t.player(3).fed = 'IRL'
730
- @t.invalid(:type => @p).should be_false
730
+ expect(@t.invalid(:type => @p)).to be_falsey
731
731
  end
732
732
 
733
733
  it "should be serializable unless invalid" do
734
- lambda { @p.serialize(@t) }.should_not raise_error
734
+ expect { @p.serialize(@t) }.not_to raise_error
735
735
  @t.site = nil;
736
- lambda { @p.serialize(@t) }.should raise_error
736
+ expect { @p.serialize(@t) }.to raise_error
737
737
  end
738
738
  end
739
739
  end