Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tilo committed Dec 11, 2023
1 parent e599a0d commit 8eb80ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/smarter_csv/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def disambiguate_headers(headers, options)
def remap_headers(headers, options)
key_mapping = options[:key_mapping]
if key_mapping.empty? || !key_mapping.is_a?(Hash) || key_mapping.keys.empty?
raise(SmarterCSV::IncorrectOption, "Error: incorrect format for key_mapping! Expecting hash with from -> to mappings")
raise(SmarterCSV::IncorrectOption, "ERROR: incorrect format for key_mapping! Expecting hash with from -> to mappings")
end

key_mapping = options[:key_mapping]
Expand Down
20 changes: 20 additions & 0 deletions spec/smarter_csv/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@
end.to raise_exception(SmarterCSV::HeaderSizeMismatch)
end
end

context 'with empty user_provided_headers' do
let(:options) { super().merge({user_provided_headers: []}) }

it 'raises an exception if the user_provided_headers is empty' do
expect do
SmarterCSV.process("#{fixture_path}/basic.csv", options)
end.to raise_exception(SmarterCSV::IncorrectOption, /ERROR: incorrect format for user_provided_headers! Expecting array with headers/)
end
end

context 'with incorrect user_provided_headers' do
let(:options) { super().merge({user_provided_headers: {}}) }

it 'raises an exception if the user_provided_headers is of incorrect type' do
expect do
SmarterCSV.process("#{fixture_path}/basic.csv", options)
end.to raise_exception(SmarterCSV::IncorrectOption, /ERROR: incorrect format for user_provided_headers! Expecting array with headers/)
end
end
end
end
end
26 changes: 26 additions & 0 deletions spec/smarter_csv/key_mapping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@
end
end

context 'with empty key_mapping' do
let(:options) { {key_mapping: {}} }

it 'raises an exception if the key_mapping is empty' do
expect do
SmarterCSV.process("#{fixture_path}/basic.csv", options)
end.to raise_exception(
SmarterCSV::IncorrectOption,
/ERROR: incorrect format for key_mapping! Expecting hash with from -> to mappings/
)
end
end

context 'with incorrect key_mapping' do
let(:options) { {key_mapping: []} }

it 'raises an exception if the key_mapping is of incorrect type' do
expect do
SmarterCSV.process("#{fixture_path}/basic.csv", options)
end.to raise_exception(
SmarterCSV::IncorrectOption,
/ERROR: incorrect format for key_mapping! Expecting hash with from -> to mappings/
)
end
end

it 'remove_values_matching' do
options = {remove_zero_values: true, key_mapping: {first_name: :vorname, last_name: :nachname} }
data = SmarterCSV.process("#{fixture_path}/basic.csv", options)
Expand Down

0 comments on commit 8eb80ee

Please sign in to comment.