dbf 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,60 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe DBF::Table do
4
+ let(:dbf_path) { fixture_path('dbase_83.dbf') }
5
+ let(:memo_path) { fixture_path('dbase_83.dbt') }
6
+ let(:table) { DBF::Table.new dbf_path }
7
+
4
8
  specify 'foxpro versions' do
5
9
  expect(DBF::Table::FOXPRO_VERSIONS.keys.sort).to eq %w(30 31 f5 fb).sort
6
10
  end
7
11
 
8
12
  describe '#initialize' do
9
- it 'accepts a DBF filename' do
10
- expect { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }.to_not raise_error
13
+ describe 'when given a path to an existing dbf file' do
14
+ it 'does not raise an error' do
15
+ expect { DBF::Table.new dbf_path }.to_not raise_error
16
+ end
11
17
  end
12
18
 
13
- it 'accepts a DBF and Memo filename' do
14
- expect { DBF::Table.new "#{DB_PATH}/dbase_83.dbf", "#{DB_PATH}/dbase_83.dbt" }.to_not raise_error
19
+ describe 'when given a path to a non-existent dbf file' do
20
+ it 'raises a DBF::FileNotFound error' do
21
+ expect { DBF::Table.new "x" }.to raise_error(DBF::FileNotFoundError, 'file not found: x')
22
+ end
23
+ end
24
+
25
+ describe 'when given paths to existing dbf and memo files' do
26
+ it 'does not raise an error' do
27
+ expect { DBF::Table.new dbf_path, memo_path }.to_not raise_error
28
+ end
15
29
  end
16
30
 
17
31
  it 'accepts an io-like data object' do
18
- data = StringIO.new File.read("#{DB_PATH}/dbase_83.dbf")
32
+ data = StringIO.new File.read(dbf_path)
19
33
  expect { DBF::Table.new data }.to_not raise_error
20
34
  end
21
35
 
22
36
  it 'accepts an io-like data and memo object' do
23
- data = StringIO.new File.read("#{DB_PATH}/dbase_83.dbf")
24
- memo = StringIO.new File.read("#{DB_PATH}/dbase_83.dbt")
37
+ data = StringIO.new File.read(dbf_path)
38
+ memo = StringIO.new File.read(memo_path)
25
39
  expect { DBF::Table.new data, memo }.to_not raise_error
26
40
  end
27
41
  end
28
42
 
29
- context "when closed" do
30
- it "closes the data and memo files" do
31
- table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
32
- table.close
33
- expect(table).to be_closed
34
- end
35
-
36
- it "closes the data" do
37
- table = DBF::Table.new "#{DB_PATH}/dbase_30.dbf"
43
+ context "#close" do
44
+ it "closes the io" do
38
45
  table.close
39
- expect(table).to be_closed
46
+ expect { table.record(1) }.to raise_error(IOError)
40
47
  end
41
48
  end
42
49
 
43
50
  describe "#schema" do
44
51
  it "matches the test schema fixture" do
45
- table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
46
- control_schema = File.read("#{DB_PATH}/dbase_83_schema.txt")
52
+ control_schema = File.read(fixture_path('dbase_83_schema.txt'))
47
53
  expect(table.schema).to eq control_schema
48
54
  end
49
55
  end
50
56
 
51
57
  describe '#to_csv' do
52
- let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
53
-
54
58
  after do
55
59
  FileUtils.rm_f 'test.csv'
56
60
  end
@@ -70,30 +74,26 @@ describe DBF::Table do
70
74
  describe 'when path param passed' do
71
75
  it 'creates a custom csv file' do
72
76
  table.to_csv('test.csv')
73
- expect(File.exists?('test.csv')).to be_true
77
+ expect(File.exists?('test.csv')).to be_truthy
74
78
  end
75
79
  end
76
80
  end
77
81
 
78
82
  describe "#record" do
79
83
  it "return nil for deleted records" do
80
- table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
81
- table.stub(:deleted_record?).and_return(true)
84
+ allow(table).to receive(:deleted_record?).and_return(true)
82
85
  expect(table.record(5)).to be_nil
83
86
  end
84
87
  end
85
88
 
86
89
  describe "#current_record" do
87
90
  it "should return nil for deleted records" do
88
- table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
89
- table.stub(:deleted_record?).and_return(true)
91
+ allow(table).to receive(:deleted_record?).and_return(true)
90
92
  expect(table.record(0)).to be_nil
91
93
  end
92
94
  end
93
95
 
94
96
  describe "#find" do
95
- let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
96
-
97
97
  describe "with index" do
98
98
  it "returns the correct record" do
99
99
  expect(table.find(5)).to eq table.record(5)
@@ -124,7 +124,7 @@ describe DBF::Table do
124
124
  end
125
125
 
126
126
  it "should AND multiple search terms" do
127
- expect(table.find(:all, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg")).to eq []
127
+ expect(table.find(:all, "ID" => 30, :IMAGE => "graphics/00000001/TBC01.jpg")).to be_empty
128
128
  end
129
129
 
130
130
  it "should match original column names" do
@@ -159,40 +159,39 @@ describe DBF::Table do
159
159
  end
160
160
  end
161
161
 
162
- describe "filename" do
163
- it 'is dbase_03.dbf' do
164
- table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
165
- expect(table.filename).to eq "dbase_03.dbf"
162
+ describe "#filename" do
163
+ it 'returns the filename as a string' do
164
+ expect(table.filename).to eq "dbase_83.dbf"
166
165
  end
167
166
  end
168
167
 
169
- describe 'has_memo_file?' do
168
+ describe '#has_memo_file?' do
170
169
  describe 'without a memo file' do
171
170
  it 'is false' do
172
- table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
173
- expect(table.has_memo_file?).to be_false
171
+ table = DBF::Table.new fixture_path('dbase_03.dbf')
172
+ expect(table.has_memo_file?).to be_falsey
174
173
  end
175
174
  end
176
175
 
177
176
  describe 'with a memo file' do
178
177
  it 'is true' do
179
- table = DBF::Table.new "#{DB_PATH}/dbase_30.dbf"
180
- expect(table.has_memo_file?).to be_true
178
+ expect(table.has_memo_file?).to be_truthy
181
179
  end
182
180
  end
183
181
  end
184
182
 
185
- describe 'columns' do
186
- let(:table) { DBF::Table.new "#{DB_PATH}/dbase_03.dbf" }
187
-
188
- it 'should have correct size' do
189
- expect(table.columns.size).to eq 31
183
+ describe '#columns' do
184
+ it 'is an array of Columns' do
185
+ expect(table.columns).to be_an(Array)
186
+ expect(table.columns).to_not be_empty
187
+ expect(table.columns.all? {|c| c.class == DBF::Column::Dbase}).to be_truthy
190
188
  end
189
+ end
191
190
 
192
- it 'should have correct names' do
193
- expect(table.columns.first.name).to eq 'Point_ID'
194
- expect(table.columns[29].name).to eq 'Easting'
191
+ describe '#column_names' do
192
+ it 'is an array of all column names' do
193
+ correct_column_names = ["ID", "CATCOUNT", "AGRPCOUNT", "PGRPCOUNT", "ORDER", "CODE", "NAME", "THUMBNAIL", "IMAGE", "PRICE", "COST", "DESC", "WEIGHT", "TAXABLE", "ACTIVE"]
194
+ expect(table.column_names).to eq correct_column_names
195
195
  end
196
196
  end
197
197
  end
198
-
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,9 @@
1
+ begin
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ rescue LoadError
5
+ end
6
+
1
7
  require 'dbf'
2
8
  require 'rspec'
3
9
 
@@ -21,3 +27,7 @@ RSpec.configure do |config|
21
27
  end
22
28
  end
23
29
  end
30
+
31
+ def fixture_path(filename)
32
+ "#{DB_PATH}/#{filename}"
33
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Keith Morrison
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
12
+ date: 2015-02-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: fastercsv
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,38 +22,11 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.5.4
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: 0.9.2
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: 0.9.2
55
30
  description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
56
31
  files.
57
32
  email: keithm@infused.org
@@ -61,12 +36,15 @@ extensions: []
61
36
  extra_rdoc_files:
62
37
  - README.md
63
38
  - CHANGELOG.md
64
- - MIT-LICENSE
39
+ - LICENSE
65
40
  files:
66
41
  - CHANGELOG.md
67
42
  - Gemfile
68
43
  - Gemfile.lock
69
- - MIT-LICENSE
44
+ - Gemfile.travis
45
+ - Gemfile.travis18
46
+ - Guardfile
47
+ - LICENSE
70
48
  - Rakefile
71
49
  - README.md
72
50
  - bin/dbf
@@ -82,6 +60,7 @@ files:
82
60
  - lib/dbf/memo/dbase4.rb
83
61
  - lib/dbf/memo/foxpro.rb
84
62
  - lib/dbf/record.rb
63
+ - lib/dbf/schema.rb
85
64
  - lib/dbf/table.rb
86
65
  - lib/dbf/version.rb
87
66
  - lib/dbf.rb
@@ -107,27 +86,28 @@ files:
107
86
  homepage: http://github.com/infused/dbf
108
87
  licenses:
109
88
  - MIT
110
- metadata: {}
111
89
  post_install_message:
112
90
  rdoc_options:
113
91
  - --charset=UTF-8
114
92
  require_paths:
115
93
  - lib
116
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
117
96
  requirements:
118
- - - '>='
97
+ - - ! '>='
119
98
  - !ruby/object:Gem::Version
120
99
  version: '0'
121
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
122
102
  requirements:
123
- - - '>='
103
+ - - ! '>='
124
104
  - !ruby/object:Gem::Version
125
105
  version: 1.3.0
126
106
  requirements: []
127
107
  rubyforge_project:
128
- rubygems_version: 2.1.5
108
+ rubygems_version: 1.8.25
129
109
  signing_key:
130
- specification_version: 4
110
+ specification_version: 3
131
111
  summary: Read xBase files
132
112
  test_files:
133
113
  - spec/dbf/column_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: db2859c1e08f0132528dfb86229d326f6cc4be33
4
- data.tar.gz: e422586329fe7da39010f33f4a6b3a967b574a60
5
- SHA512:
6
- metadata.gz: 0658b29b53be088f91f99808016854f5ef7e5f66f3d73e3a0b455d312c6a401b9861a27596500ce295b976e0fc908bdf986b111a797a309d76fcca4dcdd4e3d5
7
- data.tar.gz: e13115f3e2e3695dbfe833006a47a9ac6a17e015b284d6c03d3b4fdbc4ef4909d0c0e087e96e7d88980bac2aef0941faff2dd73ca9ccc49ecb39898e61acf245