Sha256: fdf01a98a69da493c472f32816468eda7a12c3b0765b529c95701c899b80d67f

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 KB

Contents

# spec for file-sniffing functions

require "spec_helper"
require "tempfile"

describe "mending" do
  it "should merge lines when delimiter counts don't match'" do
    filename = File.dirname(__FILE__) + "/../data/broken_psv.txt"
    results = Masticate.mend(filename, :col_sep => '|', :output => "/dev/null")
    results[:input_count].should == 7
    results[:output_count].should == 5
  end

  it "should strip trailer records" do
    filename = File.dirname(__FILE__) + "/../data/junk_trailer.txt"
    results = Masticate.mend(filename, :col_sep => '|', :output => "/dev/null", :dejunk => true)
    results[:input_count].should == 10
    results[:output_count].should == 5
    results[:headers].should == ['COL1', 'COL 2', 'Col 3', 'col-4', 'col5', 'col6']
  end

  it "should snip head fields" do
    filename = File.dirname(__FILE__) + "/../data/junk_header.csv"
    results = Masticate.mend(filename, :col_sep => ',', :snip => 1, :output => "/dev/null")
    results[:input_count].should == 6
    results[:output_count].should == 5
    results[:headers].should == %w(hospid usrorder dteorder usrsend dtesend usrdone dtedone department)
  end

  it "should unfold inlined headers" do
    filename = File.dirname(__FILE__) + "/../data/inlined_headers.csv"
    tmp = Tempfile.new('mending')
    results = Masticate.mend(filename, :col_sep => ',', :quote_char => '"', :inlined => true, :output => tmp)
    output = File.read(tmp)
    correct_output = File.read(File.dirname(__FILE__) + "/../data/inlined_headers.csv.output")

    results[:input_count].should == 11
    results[:output_count].should == 11
    results[:field_counts].should == {11 => 11}
    output.should == correct_output
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
masticate-0.2.3 spec/lib/mender_spec.rb
masticate-0.2.2 spec/lib/mender_spec.rb
masticate-0.2.1 spec/lib/mender_spec.rb
masticate-0.2 spec/lib/mender_spec.rb
masticate-0.1.5 spec/lib/mender_spec.rb
masticate-0.1.4 spec/lib/mender_spec.rb
masticate-0.1.3 spec/lib/mender_spec.rb