Skip to content

Commit

Permalink
add 'deprecation' messages for #to_csv arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mifrill committed Nov 14, 2018
1 parent 292f7e6 commit 8f52094
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/roo/formatters/csv.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module Roo
module Formatters
module CSV
def to_csv(filename = nil, sheet = default_sheet, separator: ",")
def to_csv(filename = nil, old_separator = nil, old_sheet = nil, separator: ",", sheet: default_sheet)
if old_separator
warn("[DEPRECATION] optional argument for separator is deprecated. Please use keyword argument :separator instead")
separator = old_separator
end
if old_sheet
warn("[DEPRECATION] optional argument for sheet is deprecated. Please use keyword argument :sheet instead")
sheet = old_sheet
end
if filename
File.open(filename, "w") do |file|
write_csv_content(file, sheet, separator)
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,19 @@ def sheets
it 'should convert the spreadsheet to csv using the separator when is passed on the parameter' do
expect(spreadsheet.to_csv(separator: ';')).to eq(expected_csv_with_semicolons)
end

context 'should contains the deprecation warning message' do
it 'convert the spreadsheet to csv using the separator' do
converting =-> { spreadsheet.to_csv(nil, ';') }
expect(converting.call).to eq(expected_csv_with_semicolons)
expect { converting.call }.to output(/DEPRECATION.*:separator\b/).to_stderr
end

it 'be able to arguments: filename, separator, sheet' do
converting =-> { spreadsheet.to_csv(nil, ';', spreadsheet.default_sheet) }
expect(converting.call).to eq(expected_csv_with_semicolons)
expect { converting.call }.to output(/DEPRECATION.*:sheet\b/).to_stderr
end
end
end
end

0 comments on commit 8f52094

Please sign in to comment.