require File.dirname(__FILE__) + '/spec_helper' module ICU class Tournament describe ForeignCSV do def check_player(num, first, last, results, rateable, points, other={}) p = @t.player(num) p.first_name.should == first p.last_name.should == last p.id.should == other[:id] p.rating.should == other[:rating] p.fed.should == other[:fed] p.title.should == other[:title] p.results.size.should == results p.results.select{|r| r.rateable}.size.should == rateable p.points.should == points end context "a typical tournament" do before(:all) do @csv = < 3364) check_player(2, 'April', 'Cronin', 1, 0, 1.0, :rating => 2005, :fed => 'IRL') check_player(3, 'Suzanne', 'Connolly', 1, 0, 0.5, :rating => 1950, :fed => 'IRL') check_player(4, 'Linda', 'Powell', 1, 0, 0.0, :rating => 1850, :fed => 'WLS') end end context "the rdoc example tournament" do before(:all) do @csv = < 3364) check_player(4, 'Mark', 'Orr', 2, 2, 1.5, :id => 1350) check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS', :title => 'GM') check_player(3, 'April', 'Cronin', 2, 0, 1.0, :rating => 2005, :fed => 'IRL') check_player(5, 'Bobby', 'Fischer', 1, 0, 0.0, :rating => 2700, :fed => 'USA', :title => 'GM') end end context "a tournament where someone is both a player and an opponent" do before(:all) do @csv = < 1800, :fed => 'IRL', :id => 3364) check_player(3, 'Mark', 'Orr', 2, 2, 1.0, :rating => 2100, :fed => 'IRL', :id => 1350, :title => 'IM') check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS') check_player(4, 'April', 'Cronin', 1, 0, 0.5, :rating => 2005, :fed => 'IRL') end end context "a file that contains spurious white space and other untidiness" do before(:all) do @csv = < 3364) check_player(2, 'Gary', 'Kasparov', 1, 0, 0.5, :rating => 2800, :fed => 'RUS', :title => 'GM') check_player(3, 'Mark', 'Orr', 1, 0, 0.5, :rating => 2100, :fed => 'IRL', :title => 'IM') end end context "#parse" do before(:each) do @f = ForeignCSV.new end it "should behave just like #parse! on success" do csv = <