|
384 | 384 | end |
385 | 385 | end |
386 | 386 |
|
| 387 | + context 'when force_quotes is true, even with auto-quoting disabled' do |
| 388 | + let(:options) do |
| 389 | + { |
| 390 | + force_quotes: true, |
| 391 | + disable_auto_quoting: true, # works even then |
| 392 | + } |
| 393 | + end |
| 394 | + |
| 395 | + it 'quotes all the headers and data fields' do |
| 396 | + writer = SmarterCSV::Writer.new(file_path, options) |
| 397 | + writer << data |
| 398 | + writer.finalize |
| 399 | + output = File.read(file_path) |
| 400 | + |
| 401 | + expect(output).to include("\"name\",\"age\",\"city\"#{row_sep}") |
| 402 | + expect(output).to include("\"John\",\"30\",\"New York\"#{row_sep}") |
| 403 | + end |
| 404 | + end |
| 405 | + |
387 | 406 | context 'when quote_headers is true' do |
388 | 407 | let(:options) { {quote_headers: true} } |
389 | 408 |
|
|
446 | 465 | describe 'when doing advanced mapping' do |
447 | 466 | let(:options) do |
448 | 467 | { |
| 468 | + quote_headers: true, |
449 | 469 | disable_auto_quoting: true, # ⚠️ Important: turn off auto-quoting because we're messing with it below |
450 | 470 | value_converters: { |
451 | 471 | active: ->(v) { v ? '✅' : '❌' }, |
|
470 | 490 | writer.finalize |
471 | 491 |
|
472 | 492 | output = File.read(file_path) |
473 | | - expect(output).to include("name,age,active,balance#{row_sep}") |
| 493 | + expect(output).to include("\"name\",\"age\",\"active\",\"balance\"#{row_sep}") |
474 | 494 | expect(output).to include("\"Alice\",42,\"✅\",\"$234.24\"#{row_sep}") |
475 | 495 | expect(output).to include("\"Joe\",53,\"❌\",\"$32100\"#{row_sep}") |
476 | 496 | end |
|
0 commit comments