|
16 | 16 | allow(standard_logger).to receive(:error) { |&block| block&.call } |
17 | 17 | end |
18 | 18 |
|
19 | | - shared_examples 'a logger' do |method| |
| 19 | + shared_examples 'a logger' do |method| # rubocop:disable Metrics/BlockLength |
| 20 | + let(:program) { 'program' } |
| 21 | + let(:message) { 'message' } |
| 22 | + |
20 | 23 | context 'without a block' do |
21 | | - before { logger.send(method, 'message') } |
| 24 | + before { logger.send(method, message) } |
22 | 25 |
|
23 | 26 | it 'tags the message' do |
24 | 27 | expect(standard_logger).to have_received(method).with('tag: message') |
25 | 28 | end |
| 29 | + |
| 30 | + context 'with invalid UTF-8 bytes' do |
| 31 | + let(:message) { "message\xFF".dup.force_encoding('ASCII-8BIT') } |
| 32 | + |
| 33 | + it 'tags the message, replacing invalid bytes' do |
| 34 | + expect(standard_logger).to have_received(method).with('tag: message?') |
| 35 | + end |
| 36 | + end |
26 | 37 | end |
27 | 38 |
|
28 | 39 | context 'with a block' do |
29 | | - subject(:method_call) { logger.send(method, 'program') { 'message' } } |
| 40 | + subject(:method_call) { logger.send(method, program) { message } } |
30 | 41 |
|
31 | 42 | it 'calls the logger as normal' do |
32 | 43 | method_call |
33 | | - expect(standard_logger).to have_received(method).with('program') |
| 44 | + expect(standard_logger).to have_received(method).with(program) |
34 | 45 | end |
35 | 46 |
|
36 | 47 | it { is_expected.to eq 'tag: message' } |
| 48 | + |
| 49 | + context 'with invalid UTF-8 bytes' do |
| 50 | + let(:message) { "message\xFF".dup.force_encoding('ASCII-8BIT') } |
| 51 | + |
| 52 | + it { is_expected.to eq 'tag: message?' } |
| 53 | + end |
37 | 54 | end |
38 | 55 | end |
39 | 56 |
|
|
0 commit comments