Sha256: f2751a5fb2db76ea8adb3b09d6f51b5612056b09665d28e7413a22393dad2add
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
require_relative '../../../test_helper' describe DocParser::JSONOutput do before do Log4r::Logger['docparser'].level = Log4r::ERROR end after do Log4r::Logger['docparser'].level = Log4r::INFO end it 'must create a file' do Dir.mktmpdir do |dir| filename = File.join(dir, 'test.json') DocParser::JSONOutput.new(filename: filename) File.exists?(filename).must_equal true end end it 'must save the header' do Dir.mktmpdir do |dir| filename = File.join(dir, 'test.json') output = DocParser::JSONOutput.new(filename: filename) output.header = 'test', 'the', 'header' output.close open(filename).read.must_equal '[]' end end it 'must have a header' do Dir.mktmpdir do |dir| filename = File.join(dir, 'test.json') output = DocParser::JSONOutput.new(filename: filename) lambda do output.add_row %w(aap noot mies) end.must_raise(DocParser::MissingHeaderException) end end it 'must save some rows' do Dir.mktmpdir do |dir| filename = File.join(dir, 'test.json') output = DocParser::JSONOutput.new(filename: filename) output.header = 'test', 'the', 'header' output.add_row %w(a b c) output.add_row %w(aap noot mies") output.add_row %w(aap noot) # testing empty column output.close expected = '[{"test":"a","the":"b","header":"c"}, {"test":"aap","the":"noot","header":"mies\""}, {"test":"aap","the":"noot","header":""}]'.gsub(/\s+/, '') open(filename).read.must_equal expected end end it 'must give the correct rowcount' do Dir.mktmpdir do |dir| filename = File.join(dir, 'test.json') output = DocParser::JSONOutput.new(filename: filename) output.header = 'test', 'the', 'header' output.rowcount.must_equal 0 output.add_row %w(aap noot mies) output.add_row %w(aap noot mies) output.rowcount.must_equal 2 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
docparser-0.2.0 | test/lib/docparser/output/json_output_test.rb |
docparser-0.1.6 | test/lib/docparser/output/json_output_test.rb |