spec/lib/smilodon_spec.rb in smilodon-0.2.6 vs spec/lib/smilodon_spec.rb in smilodon-0.2.7
- old
+ new
@@ -61,5 +61,48 @@
it 'calls read for each file passed to populate' do
FakePopulatorWithMultipleFiles.files.each { |f| FakePopulatorWithMultipleFiles.should_receive(:read).with(f).and_return('') }
FakePopulatorWithMultipleFiles.run
end
end
+
+describe FakePopulator, '.run' do
+ module TestPopulator
+ extend Smilodon::Populator
+ populates 'abc'
+ end
+
+ context 'header is true' do
+ let!(:csv) { ["id,name", "1,atsuya"].join("\n") }
+
+ before do
+ TestPopulator.header = true
+ TestPopulator.stub(:read).and_return(csv)
+ TestPopulator.should_receive(:process).once
+ TestPopulator.run
+ end
+
+ it 'should process csv file' do
+ TestPopulator.header.should == ["id", "name"]
+ end
+
+ it 'calls process for each non-header row' do
+ end
+ end
+
+ context 'header is false' do
+ let!(:csv) { ["id,name", "1,atsuya"].join("\n") }
+
+ before do
+ TestPopulator.header = false
+ TestPopulator.stub(:read).and_return(csv)
+ TestPopulator.should_receive(:process).twice
+ TestPopulator.run
+ end
+
+ it 'should process csv file' do
+ TestPopulator.header.should == false
+ end
+
+ it 'calls process for each row' do
+ end
+ end
+end