Sha256: 5f84aa122beca2e759c84f1a422bef038f185e437c8ead7ea21c587017116724
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
require 'spec_helper' describe Itiel::Load::CSVFile do before :each do @filename = File.expand_path("#{File.dirname(__FILE__)}/../../tmp/output.csv") File.unlink(@filename) if File.exist?(@filename) @input = [ { "id" => 1, "name" => "Subject Name" }, { "id" => 2, "name" => "Subject Name" } ] @expected_result = [ [ "id" , "name" ] , [ "1" , "Subject Name" ] , [ "2" , "Subject Name" ] ] @csv_output = Itiel::Load::CSVFile.new(@filename) end describe "the file does not exist" do before :each do @csv_output.persist(@input) @result = CSV.read(@filename, :headers => true) end it "generates a CSV file with the input data" do expect(@expected_result).to eq @result.to_a end end describe "the file already exists" do before :each do FileUtils.touch(@filename) @csv_output.persist(@input) @result = CSV.read(@filename) end it "appends to the existing data" do expect(@expected_result - [[ "id", "name" ]]).to eq @result end end describe "use append = false" do before do @csv_output = Itiel::Load::CSVFile.new(@filename, false) end describe "the file already exists" do before :each do FileUtils.touch(@filename) @csv_output.persist(@input) @result = CSV.read(@filename) end it "replaces the existing file with the input data" do expect(@expected_result).to eq @result end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
itiel-0.1.2 | spec/loader/csv_file_spec.rb |
itiel-0.1.1 | spec/loader/csv_file_spec.rb |
itiel-0.1.0 | spec/loader/csv_file_spec.rb |