spec/csv/table/table_spec.rb in smart_csv-0.0.2 vs spec/csv/table/table_spec.rb in smart_csv-0.0.5

- old
+ new

@@ -1,26 +1,38 @@ require 'smart_csv' - +require 'pry' describe "Check class CSV::Table" do - before(:each) do - data = "id,firstname,lastname\n1,One,One\n2,Two,Two\n4,Four,Four\n5,Five,Five\n6,One,One" - @data = CSV.parse(data, {:col_sep => ',', :headers => true}) - end + let(:csv_data) {"id,firstname,lastname\n1,One,One\n2,Two,Two\n4,Four,Four\n5,Five,Five\n6,One,One"} + + let(:parse_data) { CSV.parse(csv_data, {:col_sep => ',', :headers => true}) } + it "should correct create one record" do - @data.size.should eql(5) - @data.create("id"=> '13', "lastname" => '1992') - @data.size.should eql(6) - @data[-1]["id"].should eql('13') + parse_data.size.should eql(5) + parse_data.create("id"=> '13', "lastname" => '1992') + parse_data.size.should eql(6) + parse_data[-1]["id"].should eql('13') end it "should correct select records" do - @data.where('firstname' => 'One').size.should eql(2) - @data.where('firstname' => 'One').where_not('id' => '6').size.should eql(1) + parse_data.where('firstname' => 'One').size.should eql(2) + parse_data.where('firstname' => 'One').where_not('id' => '6').size.should eql(1) end it "should correct delete records" do - @data.size.should eql(5) - @data.delete_all - @data.size.should eql(0) + parse_data.size.should eql(5) + parse_data.delete_all + parse_data.size.should eql(0) + end + + it "should correct delete records" do + parse_data.size.should eql(5) + parse_data.delete_all + parse_data.size.should eql(0) + end + + it "should correct delete records" do + parse_data.size.should eql(5) + parse_data.where('firstname' => 'One').delete_all + parse_data.size.should eql(3) end end