require 'spec_helper' require 'flydata-core/string_utils' describe FlydataCore::StringUtils do let(:str) { '' } let(:expected_str) { str } subject { described_class.replace_invalid_utf8_char(str) } shared_examples 'return_expected_str' do it { is_expected.to eq(expected_str) } end context 'with non-invalid char' do context 'with ascii code str' do let(:str) { 'abcdefg' } it_behaves_like 'return_expected_str' end context 'with empty str' do let(:str) { '' } it_behaves_like 'return_expected_str' end context 'with UTF-8 char' do let(:str) { 'あいうえお' } it_behaves_like 'return_expected_str' end end context 'with invalid char' do context 'with ascii and invalid str' do let(:str) { "abc\255def" } let(:expected_str) { 'abc?def' } it_behaves_like 'return_expected_str' end context 'with UTF-8 and invalid str' do let(:str) { "あいう\255えお" } let(:expected_str) { "あいう?えお" } it_behaves_like 'return_expected_str' end end end