Skip to content

Commit

Permalink
raise error on bad data - bump version to 5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
infused committed Apr 25, 2024
1 parent b873fb8 commit 5fa1360
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 5.0.1

- Raise ArgumentError data is not a string or StringIO object

## 5.0.0

- Refactor the Column class to support non-ASCII header names
Expand Down
9 changes: 8 additions & 1 deletion lib/dbf/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,14 @@ def memo_search_path(io) # :nodoc:
end

def open_data(data) # :nodoc:
data.is_a?(StringIO) ? data : File.open(data, 'rb')
case data
when StringIO
data
when String
File.open(data, 'rb')
else
raise ArgumentError, 'data must be a file path or StringIO object'
end
rescue Errno::ENOENT
raise DBF::FileNotFoundError, "file not found: #{data}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dbf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DBF
VERSION = '5.0.0'.freeze
VERSION = '5.0.1'.freeze
end
6 changes: 6 additions & 0 deletions spec/dbf/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
end
end

describe 'when data is nil' do
it 'raises ArgumentError' do
expect { DBF::Table.new nil }.to raise_error(ArgumentError, 'data must be a file path or StringIO object')
end
end

describe 'when given paths to existing dbf and memo files' do
it 'does not raise an error' do
expect { DBF::Table.new dbf_path, memo_path }.to_not raise_error
Expand Down

0 comments on commit 5fa1360

Please sign in to comment.