dbf 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,151 +4,151 @@ shared_examples_for 'DBF' do
4
4
  specify "sum of column lengths should equal record length specified in header plus one" do
5
5
  header_record_length = table.instance_eval {@record_length}
6
6
  sum_of_column_lengths = table.columns.inject(1) {|sum, column| sum += column.length}
7
-
8
- header_record_length.should == sum_of_column_lengths
7
+
8
+ expect(header_record_length).to eq sum_of_column_lengths
9
9
  end
10
10
 
11
11
  specify "records should be instances of DBF::Record" do
12
- table.all? {|record| record.is_a?(DBF::Record)}.should be_true
12
+ expect(table.all? {|record| record.is_a?(DBF::Record)}).to be_true
13
13
  end
14
-
14
+
15
15
  specify "record count should be the same as reported in the header" do
16
- table.entries.size.should == table.record_count
16
+ expect(table.entries.size).to eq table.record_count
17
17
  end
18
-
18
+
19
19
  specify "column names should not be blank" do
20
- table.columns.all? {|column| !column.name.empty?}.should be_true
20
+ expect(table.columns.all? {|column| !column.name.empty?}).to be_true
21
21
  end
22
-
22
+
23
23
  specify "column types should be valid" do
24
24
  valid_column_types = %w(C N L D M F B G P Y T I V X @ O + 0)
25
- table.columns.all? {|column| valid_column_types.include?(column.type)}.should be_true
25
+ expect(table.columns.all? {|column| valid_column_types.include?(column.type)}).to be_true
26
26
  end
27
-
27
+
28
28
  specify "column lengths should be instances of Fixnum" do
29
- table.columns.all? {|column| column.length.is_a?(Fixnum)}.should be_true
29
+ expect(table.columns.all? {|column| column.length.is_a?(Fixnum)}).to be_true
30
30
  end
31
-
31
+
32
32
  specify "column lengths should be larger than 0" do
33
- table.columns.all? {|column| column.length > 0}.should be_true
33
+ expect(table.columns.all? {|column| column.length > 0}).to be_true
34
34
  end
35
-
35
+
36
36
  specify "column decimals should be instances of Fixnum" do
37
- table.columns.all? {|column| column.decimal.is_a?(Fixnum)}.should be_true
37
+ expect(table.columns.all? {|column| column.decimal.is_a?(Fixnum)}).to be_true
38
38
  end
39
39
  end
40
40
 
41
41
  shared_examples_for 'Foxpro DBF' do
42
42
  specify "columns should be instances of DBF::FoxproColumn" do
43
- table.columns.all? {|column| column.is_a?(DBF::Column::Foxpro)}.should be_true
43
+ expect(table.columns.all? {|column| column.is_a?(DBF::Column::Foxpro)}).to be_true
44
44
  end
45
45
  end
46
46
 
47
47
  describe DBF, "of type 03 (dBase III without memo file)" do
48
48
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_03.dbf" }
49
-
49
+
50
50
  it_should_behave_like "DBF"
51
-
51
+
52
52
  it "should report the correct version number" do
53
- table.version.should == "03"
53
+ expect(table.version).to eq "03"
54
54
  end
55
-
55
+
56
56
  it "should report the correct version description" do
57
- table.version_description.should == "dBase III without memo file"
57
+ expect(table.version_description).to eq "dBase III without memo file"
58
58
  end
59
-
59
+
60
60
  it "should determine the number of records" do
61
- table.record_count.should == 14
61
+ expect(table.record_count).to eq 14
62
62
  end
63
63
  end
64
64
 
65
65
  describe DBF, "of type 30 (Visual FoxPro)" do
66
66
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_30.dbf" }
67
-
67
+
68
68
  it_should_behave_like "DBF"
69
-
69
+
70
70
  it "should report the correct version number" do
71
- table.version.should == "30"
71
+ expect(table.version).to eq "30"
72
72
  end
73
-
73
+
74
74
  it "should report the correct version description" do
75
- table.version_description.should == "Visual FoxPro"
75
+ expect(table.version_description).to eq "Visual FoxPro"
76
76
  end
77
77
 
78
78
  it "should determine the number of records" do
79
- table.record_count.should == 34
79
+ expect(table.record_count).to eq 34
80
80
  end
81
81
  end
82
82
 
83
83
  describe DBF, "of type 31 (Visual FoxPro with AutoIncrement field)" do
84
84
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_31.dbf" }
85
-
85
+
86
86
  it_should_behave_like "DBF"
87
-
87
+
88
88
  it "should have a dBase version of 31" do
89
- table.version.should == "31"
89
+ expect(table.version).to eq "31"
90
90
  end
91
-
91
+
92
92
  it "should report the correct version description" do
93
- table.version_description.should == "Visual FoxPro with AutoIncrement field"
93
+ expect(table.version_description).to eq "Visual FoxPro with AutoIncrement field"
94
94
  end
95
-
95
+
96
96
  it "should determine the number of records" do
97
- table.record_count.should == 77
97
+ expect(table.record_count).to eq 77
98
98
  end
99
99
  end
100
100
 
101
101
  describe DBF, "of type 83 (dBase III with memo file)" do
102
102
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
103
-
103
+
104
104
  it_should_behave_like "DBF"
105
-
105
+
106
106
  it "should report the correct version number" do
107
- table.version.should == "83"
107
+ expect(table.version).to eq "83"
108
108
  end
109
-
109
+
110
110
  it "should report the correct version description" do
111
- table.version_description.should == "dBase III with memo file"
111
+ expect(table.version_description).to eq "dBase III with memo file"
112
112
  end
113
-
113
+
114
114
  it "should determine the number of records" do
115
- table.record_count.should == 67
115
+ expect(table.record_count).to eq 67
116
116
  end
117
117
  end
118
118
 
119
119
  describe DBF, "of type 8b (dBase IV with memo file)" do
120
120
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_8b.dbf" }
121
-
121
+
122
122
  it_should_behave_like "DBF"
123
-
123
+
124
124
  it "should report the correct version number" do
125
- table.version.should == "8b"
125
+ expect(table.version).to eq "8b"
126
126
  end
127
-
127
+
128
128
  it "should report the correct version description" do
129
- table.version_description.should == "dBase IV with memo file"
129
+ expect(table.version_description).to eq "dBase IV with memo file"
130
130
  end
131
-
131
+
132
132
  it "should determine the number of records" do
133
- table.record_count.should == 10
133
+ expect(table.record_count).to eq 10
134
134
  end
135
135
  end
136
136
 
137
137
  describe DBF, "of type f5 (FoxPro with memo file)" do
138
138
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_f5.dbf" }
139
-
139
+
140
140
  it_should_behave_like "DBF"
141
141
  it_should_behave_like "Foxpro DBF"
142
-
142
+
143
143
  it "should report the correct version number" do
144
- table.version.should == "f5"
144
+ expect(table.version).to eq "f5"
145
145
  end
146
-
146
+
147
147
  it "should report the correct version description" do
148
- table.version_description.should == "FoxPro with memo file"
148
+ expect(table.version_description).to eq "FoxPro with memo file"
149
149
  end
150
-
150
+
151
151
  it "should determine the number of records" do
152
- table.record_count.should == 975
152
+ expect(table.record_count).to eq 975
153
153
  end
154
154
  end
@@ -3,26 +3,34 @@ require "spec_helper"
3
3
  describe DBF::Record do
4
4
 
5
5
  describe '#to_a' do
6
+ let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
6
7
  it 'should return an ordered array of attribute values' do
7
- table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"
8
-
9
8
  record = table.record(0)
10
- record.to_a.should == ["One", 1.0, Date.new(1970, 1, 1), true, 1.23456789012346, "First memo\r\n\037 \037 \037 \037 "]
9
+ expect(record.to_a).to eq [87, 2, 0, 0, 87, "1", "Assorted Petits Fours", "graphics/00000001/t_1.jpg", "graphics/00000001/1.jpg", 0.0, 0.0, "Our Original assortment...a little taste of heaven for everyone. Let us\r\nselect a special assortment of our chocolate and pastel favorites for you.\r\nEach petit four is its own special hand decorated creation. Multi-layers of\r\nmoist cake with combinations of specialty fillings create memorable cake\r\nconfections. Varietes include; Luscious Lemon, Strawberry Hearts, White\r\nChocolate, Mocha Bean, Roasted Almond, Triple Chocolate, Chocolate Hazelnut,\r\nGrand Orange, Plum Squares, Milk chocolate squares, and Raspberry Blanc.", 5.51, true, true]
11
10
 
12
11
  record = table.record(9)
13
- record.to_a.should == ["Ten records stored in this database", 10.0, nil, false, 0.1, nil]
12
+ expect(record.to_a).to eq [34, 1, 0, 0, 34, "AB01", "Apricot Brandy Fruitcake", "graphics/00000001/t_AB01.jpg", "graphics/00000001/AB01.jpg", 37.95, 37.95, "Once tasted you will understand why we won The\r\nBoston Herald's Fruitcake Taste-off. Judges liked its generous size,\r\nluscious appearance, moist texture and fruit to cake ratio ... commented one\r\njudge \"It's a lip Smacker!\" Our signature fruitcake is baked with carefully\r\nselected ingredients that will be savored until the last moist crumb is\r\ndevoured each golden slice is brimming with Australian glaced apricots,\r\ntoasted pecans, candied orange peel, and currants, folded gently into a\r\nbrandy butter batter and slowly baked to perfection and then generously\r\nimbibed with \"Holiday Spirits\". Presented in a gift tin. (3lbs. 4oz)", 0.0, false, true]
13
+ end
14
+
15
+ describe 'with missing memo file' do
16
+ let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83_missing_memo.dbf" }
17
+
18
+ it 'returns nil values for memo fields' do
19
+ record = table.record(0)
20
+ expect(record.to_a).to eq [87, 2, 0, 0, 87, "1", "Assorted Petits Fours", "graphics/00000001/t_1.jpg", "graphics/00000001/1.jpg", 0.0, 0.0, nil, 1.0, false, false]
21
+ end
14
22
  end
15
23
  end
16
24
 
17
- describe '#==' do
25
+ describe '#==' do
18
26
  let :record do
19
27
  table = DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"
20
28
  table.record(9)
21
29
  end
22
-
30
+
23
31
  describe 'when other does not have attributes' do
24
32
  it 'is false' do
25
- (record == mock('other')).should be_false
33
+ expect((record == mock('other'))).to be_false
26
34
  end
27
35
  end
28
36
 
@@ -31,10 +39,10 @@ describe DBF::Record do
31
39
  attributes = {:x => 1, :y => 2}
32
40
  record.stub!(:attributes).and_return(attributes)
33
41
  other = mock('object', :attributes => attributes)
34
- (record == other).should be_true
42
+ expect((record == other)).to be_true
35
43
  end
36
44
  end
37
-
45
+
38
46
  end
39
47
 
40
48
  describe 'column accessors' do
@@ -42,16 +50,16 @@ describe DBF::Record do
42
50
  let(:record) { table.find(0) }
43
51
 
44
52
  it 'should have dynamic accessors for the columns' do
45
- record.should respond_to(:character)
46
- record.character.should == 'One'
47
- record.float.should == 1.23456789012346
48
- record.logical.should == true
53
+ expect(record).to respond_to(:character)
54
+ expect(record.character).to eq 'One'
55
+ expect(record.float).to eq 1.23456789012346
56
+ expect(record.logical).to eq true
49
57
  end
50
58
 
51
59
  it 'should not define accessor methods on the base class' do
52
60
  second_table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
53
61
  second_record = second_table.find(0)
54
- record.character.should == 'One'
62
+ expect(record.character).to eq 'One'
55
63
  expect { second_record.character }.to raise_error(NoMethodError)
56
64
  end
57
65
  end
@@ -63,8 +71,8 @@ describe DBF::Record do
63
71
  let(:record) { table.find(0) }
64
72
  it 'should automatically encodes to default system encoding' do
65
73
  if table.supports_encoding?
66
- record.name.encoding.should == Encoding.default_external
67
- record.name.encode("UTF-8").unpack("H4").should == ["d0b0"] # russian a
74
+ expect(record.name.encoding).to eq Encoding.default_external
75
+ expect(record.name.encode("UTF-8").unpack("H4")).to eq ["d0b0"] # russian a
68
76
  end
69
77
  end
70
78
  end
@@ -75,25 +83,25 @@ describe DBF::Record do
75
83
  let(:record) { table.find(0) }
76
84
  it 'should transcode from manually specified encoding to default system encoding' do
77
85
  if table.supports_encoding?
78
- record.name.encoding.should == Encoding.default_external
79
- record.name.encode("UTF-8").unpack("H4").should == ["d180"] # russian а encoded in cp1251 and read as if it was encoded in cp866
86
+ expect(record.name.encoding).to eq Encoding.default_external
87
+ expect(record.name.encode("UTF-8").unpack("H4")).to eq ["d180"] # russian а encoded in cp1251 and read as if it was encoded in cp866
80
88
  end
81
89
  end
82
90
  end
83
91
  end
84
-
92
+
85
93
  describe '#attributes' do
86
94
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_8b.dbf"}
87
95
  let(:record) { table.find(0) }
88
-
96
+
89
97
  it 'is a hash of attribute name/value pairs' do
90
- record.attributes.should be_a(Hash)
91
- record.attributes['CHARACTER'] == 'One'
98
+ expect(record.attributes).to be_a(Hash)
99
+ expect(record.attributes['CHARACTER']).to eq 'One'
92
100
  end
93
-
101
+
94
102
  it 'has only original field names as keys' do
95
103
  original_field_names = %w(CHARACTER DATE FLOAT LOGICAL MEMO NUMERICAL)
96
- record.attributes.keys.sort.should == original_field_names
104
+ expect(record.attributes.keys.sort).to eq original_field_names
97
105
  end
98
106
  end
99
107
  end
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
- describe DBF::Table do
3
+ describe DBF::Table do
4
4
  specify 'foxpro versions' do
5
- DBF::Table::FOXPRO_VERSIONS.keys.sort.should == %w(30 31 f5 fb).sort
5
+ expect(DBF::Table::FOXPRO_VERSIONS.keys.sort).to eq %w(30 31 f5 fb).sort
6
6
  end
7
7
 
8
8
  describe '#initialize' do
@@ -25,42 +25,42 @@ describe DBF::Table do
25
25
  expect { DBF::Table.new data, memo }.to_not raise_error
26
26
  end
27
27
  end
28
-
28
+
29
29
  context "when closed" do
30
30
  it "closes the data and memo files" do
31
31
  table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
32
32
  table.close
33
- table.should be_closed
33
+ expect(table).to be_closed
34
34
  end
35
-
35
+
36
36
  it "closes the data" do
37
37
  table = DBF::Table.new "#{DB_PATH}/dbase_30.dbf"
38
38
  table.close
39
- table.should be_closed
39
+ expect(table).to be_closed
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe "#schema" do
44
44
  it "matches the test schema fixture" do
45
45
  table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
46
46
  control_schema = File.read("#{DB_PATH}/dbase_83_schema.txt")
47
- table.schema.should == control_schema
47
+ expect(table.schema).to eq control_schema
48
48
  end
49
49
  end
50
-
50
+
51
51
  describe '#to_csv' do
52
52
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
53
-
53
+
54
54
  after do
55
55
  FileUtils.rm_f 'test.csv'
56
56
  end
57
-
57
+
58
58
  describe 'when no path param passed' do
59
59
  it 'writes to STDOUT' do
60
60
  begin
61
61
  $stdout = StringIO.new
62
62
  table.to_csv
63
- $stdout.string.should_not be_empty
63
+ expect($stdout.string).not_to be_empty
64
64
  ensure
65
65
  $stdout = STDOUT
66
66
  end
@@ -70,91 +70,91 @@ describe DBF::Table do
70
70
  describe 'when path param passed' do
71
71
  it 'creates a custom csv file' do
72
72
  table.to_csv('test.csv')
73
- File.exists?('test.csv').should be_true
73
+ expect(File.exists?('test.csv')).to be_true
74
74
  end
75
75
  end
76
76
  end
77
-
77
+
78
78
  describe "#record" do
79
79
  it "return nil for deleted records" do
80
80
  table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
81
81
  table.stub!(:deleted_record?).and_return(true)
82
- table.record(5).should be_nil
82
+ expect(table.record(5)).to be_nil
83
83
  end
84
84
  end
85
-
85
+
86
86
  describe "#current_record" do
87
87
  it "should return nil for deleted records" do
88
88
  table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
89
89
  table.stub!(:deleted_record?).and_return(true)
90
- table.record(0).should be_nil
90
+ expect(table.record(0)).to be_nil
91
91
  end
92
92
  end
93
-
93
+
94
94
  describe "#find" do
95
95
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
96
-
96
+
97
97
  describe "with index" do
98
98
  it "returns the correct record" do
99
- table.find(5).should == table.record(5)
99
+ expect(table.find(5)).to eq table.record(5)
100
100
  end
101
101
  end
102
-
103
- describe 'with array of indexes' do
102
+
103
+ describe 'with array of indexes' do
104
104
  it "returns the correct records" do
105
- table.find([1, 5, 10]).should == [table.record(1), table.record(5), table.record(10)]
105
+ expect(table.find([1, 5, 10])).to eq [table.record(1), table.record(5), table.record(10)]
106
106
  end
107
107
  end
108
-
108
+
109
109
  describe "with :all" do
110
110
  it "accepts a block" do
111
111
  records = []
112
112
  table.find(:all, :weight => 0.0) do |record|
113
113
  records << record
114
114
  end
115
- records.should == table.find(:all, :weight => 0.0)
115
+ expect(records).to eq table.find(:all, :weight => 0.0)
116
116
  end
117
117
 
118
118
  it "returns all records if options are empty" do
119
- table.find(:all).should == table.to_a
119
+ expect(table.find(:all)).to eq table.to_a
120
120
  end
121
121
 
122
122
  it "returns matching records when used with options" do
123
- table.find(:all, "WEIGHT" => 0.0).should == table.select {|r| r["weight"] == 0.0}
123
+ expect(table.find(:all, "WEIGHT" => 0.0)).to eq table.select {|r| r["weight"] == 0.0}
124
124
  end
125
125
 
126
126
  it "should AND multiple search terms" do
127
- table.find(:all, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg").should == []
127
+ expect(table.find(:all, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg")).to eq []
128
128
  end
129
-
129
+
130
130
  it "should match original column names" do
131
- table.find(:all, "WEIGHT" => 0.0).should_not be_empty
131
+ expect(table.find(:all, "WEIGHT" => 0.0)).not_to be_empty
132
132
  end
133
-
133
+
134
134
  it "matches symbolized column names" do
135
- table.find(:all, :WEIGHT => 0.0).should_not be_empty
135
+ expect(table.find(:all, :WEIGHT => 0.0)).not_to be_empty
136
136
  end
137
-
137
+
138
138
  it "matches downcased column names" do
139
- table.find(:all, "weight" => 0.0).should_not be_empty
139
+ expect(table.find(:all, "weight" => 0.0)).not_to be_empty
140
140
  end
141
-
141
+
142
142
  it "matches symbolized downcased column names" do
143
- table.find(:all, :weight => 0.0).should_not be_empty
143
+ expect(table.find(:all, :weight => 0.0)).not_to be_empty
144
144
  end
145
145
  end
146
-
146
+
147
147
  describe "with :first" do
148
148
  it "returns the first record if options are empty" do
149
- table.find(:first).should == table.record(0)
149
+ expect(table.find(:first)).to eq table.record(0)
150
150
  end
151
151
 
152
152
  it "returns the first matching record when used with options" do
153
- table.find(:first, "CODE" => "C").should == table.record(5)
153
+ expect(table.find(:first, "CODE" => "C")).to eq table.record(5)
154
154
  end
155
155
 
156
156
  it "ANDs multiple search terms" do
157
- table.find(:first, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg").should be_nil
157
+ expect(table.find(:first, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg")).to be_nil
158
158
  end
159
159
  end
160
160
  end
@@ -162,22 +162,22 @@ describe DBF::Table do
162
162
  describe "filename" do
163
163
  it 'is dbase_03.dbf' do
164
164
  table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
165
- table.filename.should == "dbase_03.dbf"
165
+ expect(table.filename).to eq "dbase_03.dbf"
166
166
  end
167
167
  end
168
-
168
+
169
169
  describe 'has_memo_file?' do
170
170
  describe 'without a memo file' do
171
171
  it 'is false' do
172
172
  table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
173
- table.has_memo_file?.should be_false
173
+ expect(table.has_memo_file?).to be_false
174
174
  end
175
175
  end
176
-
176
+
177
177
  describe 'with a memo file' do
178
178
  it 'is true' do
179
- table = DBF::Table.new "#{DB_PATH}/dbase_30.dbf"
180
- table.has_memo_file?.should be_true
179
+ table = DBF::Table.new "#{DB_PATH}/dbase_30.dbf"
180
+ expect(table.has_memo_file?).to be_true
181
181
  end
182
182
  end
183
183
  end
@@ -186,12 +186,12 @@ describe DBF::Table do
186
186
  let(:table) { DBF::Table.new "#{DB_PATH}/dbase_03.dbf" }
187
187
 
188
188
  it 'should have correct size' do
189
- table.columns.size.should == 31
189
+ expect(table.columns.size).to eq 31
190
190
  end
191
191
 
192
192
  it 'should have correct names' do
193
- table.columns.first.name.should == 'Point_ID'
194
- table.columns[29].name.should == 'Easting'
193
+ expect(table.columns.first.name).to eq 'Point_ID'
194
+ expect(table.columns[29].name).to eq 'Easting'
195
195
  end
196
196
  end
197
197
  end