1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
require 'spec_helper'
RSpec.shared_examples_for 'DBF' do
let(:header_record_length) { table.instance_eval { header.record_length } }
let(:sum_of_column_lengths) { table.columns.inject(1) { |sum, column| sum + column.length } }
specify 'sum of column lengths should equal record length specified in header plus one' do
expect(header_record_length).to eq sum_of_column_lengths
end
specify 'records should be instances of DBF::Record' do
expect(table).to all be_kind_of(DBF::Record)
end
specify 'record count should be the same as reported in the header' do
expect(table.entries.size).to eq table.record_count
end
specify 'column names should not be blank' do
table.columns.each do |column|
expect(column.name).to_not be_empty
end
end
specify 'column types should be valid' do
valid_column_types = %w[C N L D M F B G P Y T I V X @ O + 0]
table.columns.each do |column|
expect(valid_column_types).to include(column.type)
end
end
specify 'column lengths should be instances of Integer' do
table.columns.each do |column|
expect(column.length).to be_kind_of(Integer)
end
end
specify 'column lengths should be larger than 0' do
table.columns.each do |column|
expect(column.length).to be > 0
end
end
specify 'column decimals should be instances of Integer' do
table.columns.each do |column|
expect(column.decimal).to be_kind_of(Integer)
end
end
end
RSpec.describe DBF, 'of type 02 (FoxBase)' do
let(:table) { DBF::Table.new fixture('dbase_02.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '02'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'FoxBase'
end
it 'determines the number of records' do
expect(table.record_count).to eq 9
end
end
RSpec.describe DBF, 'of type 03 (dBase III without memo file)' do
let(:table) { DBF::Table.new fixture('dbase_03.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '03'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'dBase III without memo file'
end
it 'determines the number of records' do
expect(table.record_count).to eq 14
end
end
RSpec.describe DBF, 'of type 30 (Visual FoxPro)' do
let(:table) { DBF::Table.new fixture('dbase_30.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '30'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'Visual FoxPro'
end
it 'determines the number of records' do
expect(table.record_count).to eq 34
end
it 'reads memo data' do
expect(table.record(3).classes).to match(/\AAgriculture.*Farming\r\n\Z/m)
end
end
RSpec.describe DBF, 'of type 31 (Visual FoxPro with AutoIncrement field)' do
let(:table) { DBF::Table.new fixture('dbase_31.dbf') }
it_behaves_like 'DBF'
it 'has a dBase version of 31' do
expect(table.version).to eq '31'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'Visual FoxPro with AutoIncrement field'
end
it 'determines the number of records' do
expect(table.record_count).to eq 77
end
end
RSpec.describe DBF, 'of type 32 (Visual FoxPro with field type Varchar or Varbinary)' do
let(:table) { DBF::Table.new fixture('dbase_32.dbf') }
it_behaves_like 'DBF'
it 'has a dBase version of 32' do
expect(table.version).to eq '32'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'Visual FoxPro with field type Varchar or Varbinary'
end
it 'determines the number of records' do
expect(table.record_count).to eq 1
end
end
RSpec.describe DBF, 'of type 83 (dBase III with memo file)' do
let(:table) { DBF::Table.new fixture('dbase_83.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '83'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'dBase III with memo file'
end
it 'determines the number of records' do
expect(table.record_count).to eq 67
end
end
RSpec.describe DBF, 'of type 8b (dBase IV with memo file)' do
let(:table) { DBF::Table.new fixture('dbase_8b.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '8b'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'dBase IV with memo file'
end
it 'determines the number of records' do
expect(table.record_count).to eq 10
end
end
RSpec.describe DBF, 'of type 8c (unknown)' do
let(:table) { DBF::Table.new fixture('dbase_8c.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq '8c'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'dBase 7'
end
it 'determines the number of records' do
expect(table.record_count).to eq 10
end
end
RSpec.describe DBF, 'of type f5 (FoxPro with memo file)' do
let(:table) { DBF::Table.new fixture('dbase_f5.dbf') }
it_behaves_like 'DBF'
it 'reports the correct version number' do
expect(table.version).to eq 'f5'
end
it 'reports the correct version description' do
expect(table.version_description).to eq 'FoxPro with memo file'
end
it 'determines the number of records' do
expect(table.record_count).to eq 975
end
it 'reads memo data' do
expect(table.record(3).datn.to_s).to eq '1870-06-30'
end
end
|