dbf 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.DS_Store +0 -0
  2. data/History.txt +4 -0
  3. data/Manifest.txt +23 -16
  4. data/Rakefile +8 -11
  5. data/bin/dbf +40 -0
  6. data/spec/.DS_Store +0 -0
  7. data/spec/fixtures/.DS_Store +0 -0
  8. data/{test/databases/dbase_iii.dbf → spec/fixtures/dbase_03.dbf} +0 -0
  9. data/{test/databases/visual_foxpro.dbf → spec/fixtures/dbase_30.dbf} +0 -0
  10. data/{test/databases/visual_foxpro.fpt → spec/fixtures/dbase_30.fpt} +0 -0
  11. data/{test/databases/dbase_iii_memo.dbf → spec/fixtures/dbase_83.dbf} +0 -0
  12. data/{test/databases/dbase_iii_memo.dbt → spec/fixtures/dbase_83.dbt} +0 -0
  13. data/spec/fixtures/{dbase_iii_memo_schema.rb → dbase_83_schema.txt} +1 -1
  14. data/spec/fixtures/dbase_8b.dbf +0 -0
  15. data/spec/fixtures/dbase_8b.dbt +0 -0
  16. data/{test/databases/foxpro.dbf → spec/fixtures/dbase_f5.dbf} +0 -0
  17. data/{test/databases/foxpro.fpt → spec/fixtures/dbase_f5.fpt} +0 -0
  18. data/spec/functional/dbf_shared.rb +42 -0
  19. data/spec/functional/format_03_spec.rb +23 -0
  20. data/spec/functional/format_30_spec.rb +23 -0
  21. data/spec/functional/format_83_spec.rb +23 -0
  22. data/spec/functional/format_8b_spec.rb +23 -0
  23. data/spec/functional/format_f5_spec.rb +23 -0
  24. data/spec/spec_helper.rb +2 -0
  25. data/spec/{field_spec.rb → unit/field_spec.rb} +1 -1
  26. data/spec/{reader_spec.rb → unit/reader_spec.rb} +10 -10
  27. data/spec/unit/record_spec.rb +31 -0
  28. metadata +28 -20
  29. data/spec/record_spec.rb +0 -32
  30. data/test/common.rb +0 -95
  31. data/test/dbase_iii_memo_read_test.rb +0 -27
  32. data/test/dbase_iii_read_test.rb +0 -27
  33. data/test/foxpro_read_test.rb +0 -33
  34. data/test/visual_foxpro_read_test.rb +0 -27
data/.DS_Store ADDED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.5.3
2
+
3
+ * Added a standalone dbf utility (try dbf -h for help)
4
+
1
5
  == 0.5.0 / 2007-05-25
2
6
 
3
7
  * New find method
data/Manifest.txt CHANGED
@@ -1,28 +1,35 @@
1
+ .DS_Store
1
2
  History.txt
2
3
  Manifest.txt
3
4
  README.txt
4
5
  Rakefile
5
6
  benchmarks/performance.rb
6
7
  benchmarks/seek_benchmark.rb
8
+ bin/dbf
7
9
  lib/dbf.rb
8
10
  lib/dbf/field.rb
9
11
  lib/dbf/globals.rb
10
12
  lib/dbf/reader.rb
11
13
  lib/dbf/record.rb
12
- spec/field_spec.rb
13
- spec/fixtures/dbase_iii_memo_schema.rb
14
- spec/reader_spec.rb
15
- spec/record_spec.rb
14
+ spec/.DS_Store
15
+ spec/fixtures/.DS_Store
16
+ spec/fixtures/dbase_03.dbf
17
+ spec/fixtures/dbase_30.dbf
18
+ spec/fixtures/dbase_30.fpt
19
+ spec/fixtures/dbase_83.dbf
20
+ spec/fixtures/dbase_83.dbt
21
+ spec/fixtures/dbase_83_schema.txt
22
+ spec/fixtures/dbase_8b.dbf
23
+ spec/fixtures/dbase_8b.dbt
24
+ spec/fixtures/dbase_f5.dbf
25
+ spec/fixtures/dbase_f5.fpt
26
+ spec/functional/dbf_shared.rb
27
+ spec/functional/format_03_spec.rb
28
+ spec/functional/format_30_spec.rb
29
+ spec/functional/format_83_spec.rb
30
+ spec/functional/format_8b_spec.rb
31
+ spec/functional/format_f5_spec.rb
16
32
  spec/spec_helper.rb
17
- test/common.rb
18
- test/databases/dbase_iii.dbf
19
- test/databases/dbase_iii_memo.dbf
20
- test/databases/dbase_iii_memo.dbt
21
- test/databases/foxpro.dbf
22
- test/databases/foxpro.fpt
23
- test/databases/visual_foxpro.dbf
24
- test/databases/visual_foxpro.fpt
25
- test/dbase_iii_memo_read_test.rb
26
- test/dbase_iii_read_test.rb
27
- test/foxpro_read_test.rb
28
- test/visual_foxpro_read_test.rb
33
+ spec/unit/field_spec.rb
34
+ spec/unit/reader_spec.rb
35
+ spec/unit/record_spec.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
2
2
  require 'spec/rake/spectask'
3
3
 
4
4
  PKG_NAME = "dbf"
5
- PKG_VERSION = "0.5.2"
5
+ PKG_VERSION = "0.5.3"
6
6
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
7
7
 
8
8
  Hoe.new PKG_NAME, PKG_VERSION do |p|
@@ -16,18 +16,15 @@ Hoe.new PKG_NAME, PKG_VERSION do |p|
16
16
  p.need_zip = true
17
17
  end
18
18
 
19
- desc 'Run tests'
20
- task :default => [:spec, :test]
21
-
22
- desc 'Run tests'
23
- Rake::TestTask.new :test do |t|
24
- t.libs << "test"
25
- t.pattern = 'test/*_test.rb'
26
- t.verbose = true
27
- end
19
+ task :default => [:spec]
28
20
 
29
21
  desc "Run specs"
30
22
  Spec::Rake::SpecTask.new :spec do |t|
31
- # t.spec_opts = ["-f specdoc"]
32
23
  t.spec_files = FileList['spec/**/*spec.rb']
33
24
  end
25
+
26
+ desc "Run spec docs"
27
+ Spec::Rake::SpecTask.new :specdoc do |t|
28
+ t.spec_opts = ["-f specdoc"]
29
+ t.spec_files = FileList['spec/**/*spec.rb']
30
+ end
data/bin/dbf ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby -ws
2
+
3
+ require 'rubygems'
4
+ require 'dbf'
5
+
6
+ $a ||= false
7
+ $s ||= false
8
+
9
+ if defined? $h then
10
+ puts "usage: #{File.basename(__FILE__)} [-h|-s|-a] filename"
11
+ puts " -h = print this message"
12
+ puts " -s = print summary information"
13
+ puts " -a = create an ActiveRecord::Schema"
14
+ else
15
+
16
+ filename = ARGV.shift
17
+ abort "You must supply a filename on the command line" unless filename
18
+
19
+ # create an ActiveRecord::Schema
20
+ if $a
21
+ reader = DBF::Reader.new filename
22
+ puts reader.schema
23
+ end
24
+
25
+ if $s
26
+ reader = DBF::Reader.new filename
27
+ puts
28
+ puts "Database: #{filename}"
29
+ puts "Type: (#{reader.version}) #{reader.version_description}"
30
+ puts "Memo Type: #{reader.memo_file_format}" if reader.has_memo_file?
31
+ puts "Records: #{reader.record_count}"
32
+
33
+ puts "\nFields:"
34
+ puts "Name Type Length Decimal"
35
+ puts "-" * 78
36
+ reader.fields.each do |f|
37
+ puts "%-16s %-10s %-10s %-10s" % [f.name, f.type, f.length, f.decimal]
38
+ end
39
+ end
40
+ end
data/spec/.DS_Store ADDED
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  ActiveRecord::Schema.define do
2
- create_table "dbase_iii_memo" do |t|
2
+ create_table "dbase_83" do |t|
3
3
  t.column "ID", :integer
4
4
  t.column "CATCOUNT", :integer
5
5
  t.column "AGRPCOUNT", :integer
Binary file
Binary file
@@ -0,0 +1,42 @@
1
+ describe DBF, :shared => true do
2
+ specify "number of records found should equal number of records calculated from the header information" do
3
+ @reader.record_count.should == @reader.records.size
4
+ end
5
+
6
+ specify "sum of field lengths should equal record length specified in header" do
7
+ header_record_length = @reader.instance_eval {@record_length}
8
+ sum_of_field_lengths = @reader.fields.inject(1) {|sum, field| sum + field.length}
9
+
10
+ header_record_length.should == sum_of_field_lengths
11
+ end
12
+
13
+ specify "records should be instances of DBF::Record" do
14
+ @reader.records.all? {|record| record.should be_an_instance_of(DBF::Record)}
15
+ end
16
+
17
+ specify "fields should be instances of DBF::Field" do
18
+ @reader.fields.all? {|field| field.should be_an_instance_of(DBF::Field)}
19
+ end
20
+
21
+ specify "field names should not be blank" do
22
+ @reader.fields.all? {|field| field.name.should_not be_empty}
23
+ end
24
+
25
+ specify "field types should be valid" do
26
+ valid_field_types = %w(C N L D M F B G P Y T I V X @ O +)
27
+ @reader.fields.all? {|field| valid_field_types.should include(field.type)}
28
+ end
29
+
30
+ specify "field lengths should be instances of Fixnum" do
31
+ @reader.fields.all? {|field| field.length.should be_an_instance_of(Fixnum)}
32
+ end
33
+
34
+ specify "field lengths should be larger than 0" do
35
+ @reader.fields.all? {|field| field.length.should > 0}
36
+ end
37
+
38
+ specify "field decimals should be instances of Fixnum" do
39
+ @reader.fields.all? {|field| field.decimal.should be_an_instance_of(Fixnum)}
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require File.dirname(__FILE__) + "/dbf_shared"
3
+
4
+ describe DBF, "of type 03 (dBase III without memo file)" do
5
+ before(:each) do
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_03.dbf"
7
+ end
8
+
9
+ it_should_behave_like "DBF"
10
+
11
+ it "should report the correct version number" do
12
+ @reader.version.should == "03"
13
+ end
14
+
15
+ it "should have a memo file" do
16
+ @reader.should_not have_memo_file
17
+ end
18
+
19
+ it "should report the correct memo type" do
20
+ @reader.memo_file_format.should be_nil
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require File.dirname(__FILE__) + "/dbf_shared"
3
+
4
+ describe DBF, "of type 30 (Visual FoxPro)" do
5
+ before(:each) do
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_30.dbf"
7
+ end
8
+
9
+ it_should_behave_like "DBF"
10
+
11
+ it "should report the correct version number" do
12
+ @reader.version.should == "30"
13
+ end
14
+
15
+ it "should have a memo file" do
16
+ @reader.should have_memo_file
17
+ end
18
+
19
+ it "should report the correct memo type" do
20
+ @reader.memo_file_format.should == :fpt
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require File.dirname(__FILE__) + "/dbf_shared"
3
+
4
+ describe DBF, "of type 83 (dBase III with memo file)" do
5
+ before(:each) do
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
7
+ end
8
+
9
+ it_should_behave_like "DBF"
10
+
11
+ it "should report the correct version number" do
12
+ @reader.version.should == "83"
13
+ end
14
+
15
+ it "should have a memo file" do
16
+ @reader.should have_memo_file
17
+ end
18
+
19
+ it "should report the correct memo type" do
20
+ @reader.memo_file_format.should == :dbt
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require File.dirname(__FILE__) + "/dbf_shared"
3
+
4
+ describe DBF, "of type 8b (dBase IV with memo file)" do
5
+ before(:each) do
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_8b.dbf"
7
+ end
8
+
9
+ it_should_behave_like "DBF"
10
+
11
+ it "should report the correct version number" do
12
+ @reader.version.should == "8b"
13
+ end
14
+
15
+ it "should have a memo file" do
16
+ @reader.should have_memo_file
17
+ end
18
+
19
+ it "should report the correct memo type" do
20
+ @reader.memo_file_format.should == :dbt
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require File.dirname(__FILE__) + "/dbf_shared"
3
+
4
+ describe DBF, "of type f5 (FoxPro with memo file)" do
5
+ before(:each) do
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_f5.dbf"
7
+ end
8
+
9
+ it_should_behave_like "DBF"
10
+
11
+ it "should report the correct version number" do
12
+ @reader.version.should == "f5"
13
+ end
14
+
15
+ it "should have a memo file" do
16
+ @reader.should have_memo_file
17
+ end
18
+
19
+ it "should report the correct memo type" do
20
+ @reader.memo_file_format.should == :fpt
21
+ end
22
+
23
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,8 @@ require "rubygems"
3
3
  require "spec"
4
4
  require "dbf"
5
5
 
6
+ DB_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH)
7
+
6
8
  Spec::Runner.configure do |config|
7
9
  config.mock_with :mocha
8
10
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe DBF::Field, "when initialized" do
4
4
 
@@ -1,9 +1,9 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe DBF::Reader, "when initialized" do
4
4
 
5
5
  before(:all) do
6
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
6
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
7
7
  end
8
8
 
9
9
  it "should load the data file" do
@@ -44,7 +44,7 @@ end
44
44
  describe DBF::Reader, "when the in_memory flag is true" do
45
45
 
46
46
  before(:each) do
47
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
47
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
48
48
  end
49
49
 
50
50
  it "should build the records array from disk only on the first request" do
@@ -65,7 +65,7 @@ end
65
65
  describe DBF::Reader, "when the in_memory flag is false" do
66
66
 
67
67
  before(:each) do
68
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
68
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
69
69
  end
70
70
 
71
71
  it "should read the records from disk on every request" do
@@ -78,8 +78,8 @@ end
78
78
  describe DBF::Reader, "schema" do
79
79
 
80
80
  it "should match test schema " do
81
- reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
82
- control_schema = File.read(File.dirname(__FILE__) + '/fixtures/dbase_iii_memo_schema.rb')
81
+ reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
82
+ control_schema = File.read(File.dirname(__FILE__) + '/../fixtures/dbase_83_schema.txt')
83
83
 
84
84
  reader.schema.should == control_schema
85
85
  end
@@ -89,7 +89,7 @@ end
89
89
  describe DBF::Reader, "find(index)" do
90
90
 
91
91
  before(:all) do
92
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
92
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
93
93
  end
94
94
 
95
95
  it "should return the correct record" do
@@ -105,7 +105,7 @@ end
105
105
  describe DBF::Reader, "find(:all)" do
106
106
 
107
107
  before(:all) do
108
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
108
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
109
109
  end
110
110
 
111
111
  it "should return all records if options are empty" do
@@ -124,7 +124,7 @@ end
124
124
  describe DBF::Reader, "find(:first)" do
125
125
 
126
126
  before(:all) do
127
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
127
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
128
128
  end
129
129
 
130
130
  it "should return the first record if options are empty" do
@@ -143,7 +143,7 @@ end
143
143
  describe DBF::Reader do
144
144
 
145
145
  before(:each) do
146
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
146
+ @reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
147
147
  end
148
148
 
149
149
  it "should reload all data when sent #reload!" do
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe DBF::Record, "when initialized" do
4
+
5
+ it "should typecast number fields with decimals == 0 to Integer" do
6
+ reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
7
+ reader.field("ID").type.should == "N"
8
+ reader.field("ID").decimal.should == 0
9
+ reader.records.all? {|record| record["ID"].should be_kind_of(Integer)}
10
+ end
11
+
12
+ it "should typecast number fields with decimals > 0 to Float" do
13
+ reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
14
+ reader.field("ID").type.should == "N"
15
+ reader.field("COST").decimal.should == 2
16
+ reader.records.all? {|record| record["COST"].should be_kind_of(Float)}
17
+ end
18
+
19
+ it "should typecast memo fields to String" do
20
+ reader = DBF::Reader.new "#{DB_PATH}/dbase_83.dbf"
21
+ reader.field("DESC").type.should == "M"
22
+ reader.records.all? {|record| record["DESC"].should be_kind_of(String)}
23
+ end
24
+
25
+ it "should typecast logical fields to True or False" do
26
+ reader = DBF::Reader.new "#{DB_PATH}/dbase_30.dbf"
27
+ reader.field("WEBINCLUDE").type.should == "L"
28
+ reader.records.all? {|record| record["WEBINCLUDE"].should satisfy {|v| v == true || v == false}}
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: dbf
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
7
- date: 2007-06-12 00:00:00 -07:00
6
+ version: 0.5.3
7
+ date: 2007-06-16 00:00:00 -07:00
8
8
  summary: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
9
9
  require_paths:
10
10
  - lib
@@ -29,34 +29,41 @@ post_install_message:
29
29
  authors:
30
30
  - Keith Morrison
31
31
  files:
32
+ - .DS_Store
32
33
  - History.txt
33
34
  - Manifest.txt
34
35
  - README.txt
35
36
  - Rakefile
36
37
  - benchmarks/performance.rb
37
38
  - benchmarks/seek_benchmark.rb
39
+ - bin/dbf
38
40
  - lib/dbf.rb
39
41
  - lib/dbf/field.rb
40
42
  - lib/dbf/globals.rb
41
43
  - lib/dbf/reader.rb
42
44
  - lib/dbf/record.rb
43
- - spec/field_spec.rb
44
- - spec/fixtures/dbase_iii_memo_schema.rb
45
- - spec/reader_spec.rb
46
- - spec/record_spec.rb
45
+ - spec/.DS_Store
46
+ - spec/fixtures/.DS_Store
47
+ - spec/fixtures/dbase_03.dbf
48
+ - spec/fixtures/dbase_30.dbf
49
+ - spec/fixtures/dbase_30.fpt
50
+ - spec/fixtures/dbase_83.dbf
51
+ - spec/fixtures/dbase_83.dbt
52
+ - spec/fixtures/dbase_83_schema.txt
53
+ - spec/fixtures/dbase_8b.dbf
54
+ - spec/fixtures/dbase_8b.dbt
55
+ - spec/fixtures/dbase_f5.dbf
56
+ - spec/fixtures/dbase_f5.fpt
57
+ - spec/functional/dbf_shared.rb
58
+ - spec/functional/format_03_spec.rb
59
+ - spec/functional/format_30_spec.rb
60
+ - spec/functional/format_83_spec.rb
61
+ - spec/functional/format_8b_spec.rb
62
+ - spec/functional/format_f5_spec.rb
47
63
  - spec/spec_helper.rb
48
- - test/common.rb
49
- - test/databases/dbase_iii.dbf
50
- - test/databases/dbase_iii_memo.dbf
51
- - test/databases/dbase_iii_memo.dbt
52
- - test/databases/foxpro.dbf
53
- - test/databases/foxpro.fpt
54
- - test/databases/visual_foxpro.dbf
55
- - test/databases/visual_foxpro.fpt
56
- - test/dbase_iii_memo_read_test.rb
57
- - test/dbase_iii_read_test.rb
58
- - test/foxpro_read_test.rb
59
- - test/visual_foxpro_read_test.rb
64
+ - spec/unit/field_spec.rb
65
+ - spec/unit/reader_spec.rb
66
+ - spec/unit/record_spec.rb
60
67
  test_files: []
61
68
 
62
69
  rdoc_options:
@@ -66,8 +73,9 @@ extra_rdoc_files:
66
73
  - History.txt
67
74
  - Manifest.txt
68
75
  - README.txt
69
- executables: []
70
-
76
+ - spec/fixtures/dbase_83_schema.txt
77
+ executables:
78
+ - dbf
71
79
  extensions: []
72
80
 
73
81
  requirements: []
data/spec/record_spec.rb DELETED
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DBF::Record, "when initialized" do
4
-
5
- before(:each) do
6
- @reader = DBF::Reader.new File.dirname(__FILE__) + '/../test/databases/dbase_iii_memo.dbf'
7
- @record = @reader.record(5)
8
- end
9
-
10
- it "should typecast number fields with decimals == 0 to Integer" do
11
- @reader.field("ID").type == "N"
12
- @reader.field("ID").decimal.should == 0
13
- @record["ID"].should be_kind_of(Integer)
14
- end
15
-
16
- it "should typecast number fields with decimals > 0 to Float" do
17
- @reader.field("ID").type == "N"
18
- @reader.field("COST").decimal.should == 2
19
- @record["COST"].should be_kind_of(Float)
20
- end
21
-
22
- it "should typecast memo fields to String" do
23
- @reader.field("DESC").type == "M"
24
- @record["DESC"].should be_kind_of(String)
25
- end
26
-
27
- it "should typecast logical fields to True or False" do
28
- @reader.field("TAXABLE").type == "L"
29
- @record["TAXABLE"].should be_kind_of(FalseClass)
30
- end
31
-
32
- end
data/test/common.rb DELETED
@@ -1,95 +0,0 @@
1
- module CommonTests
2
- module Read
3
-
4
- def test_version
5
- assert_equal @controls[:version], @dbf.version
6
- assert_equal @dbf.instance_eval("DBF::VERSION_DESCRIPTIONS['#{@dbf.version}']"), @dbf.version_description
7
- end
8
-
9
- def test_has_memo_file
10
- assert_equal @controls[:has_memo_file], @dbf.has_memo_file?
11
- end
12
-
13
- def test_memo_file_format
14
- assert_equal @controls[:memo_file_format], @dbf.memo_file_format
15
- end
16
-
17
- def test_records
18
- assert_kind_of Array, @dbf.records
19
- assert_kind_of Array, @dbf.rows
20
- assert(@dbf.records.all? {|record| record.is_a?(DBF::Record)})
21
- end
22
-
23
- # Does the header info match the actual fields found?
24
- def test_field_count
25
- assert_equal @controls[:field_count], @dbf.field_count
26
- assert_equal @dbf.field_count, @dbf.fields.size, "header field_count does not equal actual field count"
27
- end
28
-
29
- # Does the header info match the actual number of records found?
30
- def test_record_count
31
- assert_equal @controls[:record_count], @dbf.record_count
32
- assert_equal @dbf.record_count, @dbf.records.size, "header record_count does not equal actual record count"
33
- end
34
-
35
- def test_record_length
36
- assert_equal @controls[:record_length], @dbf.instance_eval {@record_length}
37
- assert_equal @controls[:record_length], @dbf.fields.inject(1) {|sum, field| sum + field.length}
38
- end
39
-
40
- def test_field_attributes
41
- @dbf.fields.each do |field|
42
- assert_kind_of DBF::Field, field
43
- assert field.name.is_a?(String) && !field.name.empty?
44
- assert %w(C N L D M F B G P Y T I V X @ O +).include?(field.type)
45
- assert_kind_of Fixnum, field.length
46
- assert field.length > 0
47
- assert_kind_of Fixnum, field.decimal
48
- end
49
- end
50
-
51
- def test_random_records
52
- 10.times do
53
- record_num = rand(@controls[:record_count])
54
- assert_equal @dbf.records[record_num], @dbf.record(record_num)
55
- end
56
- end
57
-
58
- def test_character_fields
59
- @controls[:testable_character_field_names].each do |name|
60
- assert(@dbf.records.any? {|record| record[name].is_a?(String)})
61
- end
62
- end
63
-
64
- def test_date_fields
65
- @controls[:testable_date_field_names].each do |name|
66
- assert(@dbf.records.any? {|record| record[name].is_a?(Date) || record[name].is_a?(Time)})
67
- end
68
- end
69
-
70
- def test_integer_numeric_fields
71
- @controls[:testable_integer_field_names].each do |name|
72
- assert(@dbf.records.any? {|record| record[name].is_a?(Fixnum)})
73
- end
74
- end
75
-
76
- def test_float_numeric_fields
77
- @controls[:testable_float_field_names].each do |name|
78
- assert(@dbf.records.any? {|record| record[name].is_a?(Float)})
79
- end
80
- end
81
-
82
- def test_logical_fields
83
- # need a test database that has a logical field
84
- end
85
-
86
- def test_memo_fields
87
- @controls[:testable_memo_field_names].each do |name|
88
- assert(@dbf.records.any? {|record| record[name].is_a?(String)}, "expected a String")
89
- assert(@dbf.records.any? {|record| record[name].is_a?(String) && record[name].size > 1})
90
- end
91
- end
92
-
93
- end
94
-
95
- end
@@ -1,27 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
- require 'test/unit'
3
- require 'dbf'
4
- require 'common'
5
-
6
- class DBaseIIIWithMemoReadTest < Test::Unit::TestCase
7
- include CommonTests::Read
8
-
9
- def setup
10
- @controls = {
11
- :version => "83",
12
- :has_memo_file => true,
13
- :memo_file_format => :dbt,
14
- :field_count => 15,
15
- :record_count => 67,
16
- :record_length => 805,
17
- :testable_character_field_names => ["CODE"],
18
- :testable_date_field_names => [],
19
- :testable_integer_field_names => ["AGRPCOUNT"],
20
- :testable_float_field_names => ["PRICE"],
21
- :testable_logical_field_names => ["TAXABLE"],
22
- :testable_memo_field_names => ["DESC"]
23
- }
24
- @dbf = DBF::Reader.new(File.join(File.dirname(__FILE__),'databases', 'dbase_iii_memo.dbf'))
25
- end
26
-
27
- end
@@ -1,27 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
- require 'test/unit'
3
- require 'dbf'
4
- require 'common'
5
-
6
- class DBaseIIIReadTest < Test::Unit::TestCase
7
- include CommonTests::Read
8
-
9
- def setup
10
- @controls = {
11
- :version => "03",
12
- :has_memo_file => false,
13
- :memo_file_format => nil,
14
- :field_count => 31,
15
- :record_count => 14,
16
- :record_length => 590,
17
- :testable_character_field_names => ["Shape"],
18
- :testable_date_field_names => ["Date_Visit"],
19
- :testable_integer_field_names => ["Filt_Pos"],
20
- :testable_float_field_names => ["Max_PDOP"],
21
- :testable_logical_field_names => [],
22
- :testable_memo_field_names => []
23
- }
24
- @dbf = DBF::Reader.new "#{File.dirname(__FILE__)}/databases/dbase_iii.dbf"
25
- end
26
-
27
- end
@@ -1,33 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
- require 'test/unit'
3
- require 'dbf'
4
- require 'common'
5
-
6
- class FoxproReadTest < Test::Unit::TestCase
7
- include CommonTests::Read
8
-
9
- def setup
10
- @controls = {
11
- :version => "f5",
12
- :has_memo_file => true,
13
- :memo_file_format => :fpt,
14
- :field_count => 59,
15
- :record_count => 975,
16
- :record_length => 969,
17
- :testable_character_field_names => ["NOM"],
18
- :testable_date_field_names => ["DATN"],
19
- :testable_integer_field_names => ["NF"],
20
- :testable_float_field_names => [],
21
- :testable_logical_field_names => [],
22
- :testable_memo_field_names => ["OBSE"]
23
- }
24
- @dbf = DBF::Reader.new "#{File.dirname(__FILE__)}/databases/foxpro.dbf"
25
- end
26
-
27
- # make sure we're grabbing the correct memo
28
- def test_memo_contents
29
- assert_equal "jos\202 vicente salvador\r\ncapell\205: salvador vidal\r\nen n\202ixer, les castellers li van fer un pilar i el van entregar al seu pare.",
30
- @dbf.records[3]['OBSE']
31
- end
32
-
33
- end
@@ -1,27 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
- require 'test/unit'
3
- require 'dbf'
4
- require 'common'
5
-
6
- class VisualFoxproReadTest < Test::Unit::TestCase
7
- include CommonTests::Read
8
-
9
- def setup
10
- @controls = {
11
- :version => "30",
12
- :has_memo_file => true,
13
- :memo_file_format => :fpt,
14
- :field_count => 145,
15
- :record_count => 34,
16
- :record_length => 3907,
17
- :testable_character_field_names => [],
18
- :testable_date_field_names => [],
19
- :testable_integer_field_names => ["IMAGENO"],
20
- :testable_float_field_names => [],
21
- :testable_logical_field_names => [],
22
- :testable_memo_field_names => ["CREDIT"]
23
- }
24
- @dbf = DBF::Reader.new(File.join(File.dirname(__FILE__),'databases', 'visual_foxpro.dbf'))
25
- end
26
-
27
- end