Sha256: 0449705ed25827eb640e0aeb50932132e0da44eb69265970a67fd7f2b7154c4b

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

require 'helper'

class TestCsv2json < Test::Unit::TestCase
    SEPS = {:comma => ',', :pipe => '|', :semicolon => ';'}

    should "parse some test files" do
        fixtures_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))

        Dir.chdir(fixtures_dir) do
            Dir.glob('*.csv') do |filename|
                filename_parts = File.basename(filename, ".csv").split('_')
                json_template = filename_parts[0] + '.json'

                print "Testing csv2json against #{filename}\n"

                File.open(filename, "r") do |input|
                    output = StringIO.new()
                    CSV2JSON.parse(input, output, nil, {:col_sep => SEPS[filename_parts[1].to_sym]}, {:pretty => true} )
                    template = File.read(json_template)

                    output.pos = 0
                    assert JSON.parse(template) == JSON.parse(output.read), "Content doesn't match"
                end
            end
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv2json-0.3.0 test/test_csv2json.rb