-
Notifications
You must be signed in to change notification settings - Fork 19
/
utf8_spec.rb
56 lines (42 loc) · 1.53 KB
/
utf8_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'
require 'ably/models/message_encoders/utf8'
describe Ably::Models::MessageEncoders::Utf8 do
let(:string_ascii) { 'string'.encode(Encoding::ASCII_8BIT) }
let(:string_utf8) { 'string'.encode(Encoding::UTF_8) }
let(:client) { instance_double('Ably::Realtime::Client') }
subject { Ably::Models::MessageEncoders::Utf8.new(client) }
context '#decode' do
before do
subject.decode message, {}
end
context 'message with utf8 payload' do
let(:message) { { data: string_ascii, encoding: 'utf-8' } }
it 'sets the encoding' do
expect(message[:data]).to eq(string_utf8)
expect(message[:data].encoding).to eql(Encoding::UTF_8)
end
it 'strips the encoding' do
expect(message[:encoding]).to be_nil
end
end
context 'message with utf8 payload before other payloads' do
let(:message) { { data: string_utf8, encoding: 'json/utf-8' } }
it 'sets the encoding' do
expect(message[:data]).to eql(string_utf8)
expect(message[:data].encoding).to eql(Encoding::UTF_8)
end
it 'strips the encoding' do
expect(message[:encoding]).to eql('json')
end
end
context 'message with another payload' do
let(:message) { { data: string_ascii, encoding: 'json' } }
it 'leaves the message data intact' do
expect(message[:data]).to eql(string_ascii)
end
it 'leaves the encoding intact' do
expect(message[:encoding]).to eql('json')
end
end
end
end