pusher-fake 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ describe PusherFake::Channel::Private do
4
4
  subject { PusherFake::Channel::Private }
5
5
 
6
6
  it "inherits from public channel" do
7
- subject.ancestors.should include(PusherFake::Channel::Public)
7
+ expect(subject.ancestors).to include(PusherFake::Channel::Public)
8
8
  end
9
9
  end
10
10
 
@@ -24,46 +24,52 @@ describe PusherFake::Channel::Private, "#add" do
24
24
 
25
25
  it "authorizes the connection" do
26
26
  subject.stubs(authorized?: nil)
27
+
27
28
  subject.add(connection, data)
28
- subject.should have_received(:authorized?).with(connection, data)
29
+
30
+ expect(subject).to have_received(:authorized?).with(connection, data)
29
31
  end
30
32
 
31
33
  it "adds the connection to the channel when authorized" do
32
34
  subject.stubs(authorized?: true)
35
+
33
36
  subject.add(connection, data)
34
- connections.should have_received(:push).with(connection)
37
+
38
+ expect(connections).to have_received(:push).with(connection)
35
39
  end
36
40
 
37
41
  it "successfully subscribes the connection when authorized" do
38
42
  subject.stubs(authorized?: true)
43
+
39
44
  subject.add(connection, data)
40
- connection.should have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
45
+
46
+ expect(connection).to have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
41
47
  end
42
48
 
43
49
  it "triggers channel occupied webhook for the first connection added when authorized" do
44
50
  subject.unstub(:connections)
45
51
  subject.stubs(authorized?: true)
46
52
 
47
- subject.add(connection, data)
48
- PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
49
- subject.add(connection, data)
50
- PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
53
+ 2.times { subject.add(connection, data) }
54
+
55
+ expect(PusherFake::Webhook).to have_received(:trigger).with("channel_occupied", channel: name).once
51
56
  end
52
57
 
53
58
  it "unsuccessfully subscribes the connection when not authorized" do
54
59
  subject.stubs(authorized?: false)
60
+
55
61
  subject.add(connection, data)
56
- connection.should have_received(:emit).with("pusher_internal:subscription_error", {}, subject.name)
62
+
63
+ expect(connection).to have_received(:emit).with("pusher_internal:subscription_error", {}, subject.name)
57
64
  end
58
65
 
59
66
  it "does not trigger channel occupied webhook when not authorized" do
60
67
  subject.unstub(:connections)
61
68
  subject.stubs(authorized?: false)
62
69
 
63
- subject.add(connection, data)
64
- PusherFake::Webhook.should have_received(:trigger).never
65
- subject.add(connection, data)
66
- PusherFake::Webhook.should have_received(:trigger).never
70
+ 2.times { subject.add(connection, data) }
71
+
72
+ expect(PusherFake::Webhook).to have_received(:trigger).never
67
73
  end
68
74
  end
69
75
 
@@ -83,11 +89,15 @@ describe PusherFake::Channel::Private, "#authentication_for" do
83
89
 
84
90
  it "generates a signature" do
85
91
  subject.authentication_for(id)
86
- OpenSSL::HMAC.should have_received(:hexdigest).with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
92
+
93
+ expect(OpenSSL::HMAC).to have_received(:hexdigest)
94
+ .with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
87
95
  end
88
96
 
89
97
  it "returns the authentication string" do
90
- subject.authentication_for(id).should == "#{configuration.key}:#{signature}"
98
+ string = subject.authentication_for(id)
99
+
100
+ expect(string).to eq("#{configuration.key}:#{signature}")
91
101
  end
92
102
  end
93
103
 
@@ -108,11 +118,15 @@ describe PusherFake::Channel::Private, "#authentication_for, with channel data"
108
118
 
109
119
  it "generates a signature" do
110
120
  subject.authentication_for(id, channel_data)
111
- OpenSSL::HMAC.should have_received(:hexdigest).with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
121
+
122
+ expect(OpenSSL::HMAC).to have_received(:hexdigest)
123
+ .with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
112
124
  end
113
125
 
114
126
  it "returns the authentication string" do
115
- subject.authentication_for(id, channel_data).should == "#{configuration.key}:#{signature}"
127
+ string = subject.authentication_for(id, channel_data)
128
+
129
+ expect(string).to eq("#{configuration.key}:#{signature}")
116
130
  end
117
131
  end
118
132
 
@@ -132,16 +146,19 @@ describe PusherFake::Channel::Private, "#authorized?" do
132
146
 
133
147
  it "generates authentication for the connection socket ID" do
134
148
  subject.authorized?(connection, data)
135
- subject.should have_received(:authentication_for).with(socket.object_id, channel_data)
149
+
150
+ expect(subject).to have_received(:authentication_for).with(socket.object_id, channel_data)
136
151
  end
137
152
 
138
153
  it "returns true if the authentication matches" do
139
154
  subject.stubs(authentication_for: authentication)
140
- subject.authorized?(connection, data).should be_true
155
+
156
+ expect(subject).to be_authorized(connection, data)
141
157
  end
142
158
 
143
159
  it "returns false if the authentication matches" do
144
160
  subject.stubs(authentication_for: "")
145
- subject.authorized?(connection, data).should be_false
161
+
162
+ expect(subject).to_not be_authorized(connection, data)
146
163
  end
147
164
  end
@@ -7,12 +7,14 @@ describe PusherFake::Channel::Public do
7
7
 
8
8
  it "assigns the provided name" do
9
9
  channel = subject.new(name)
10
- channel.name.should == name
10
+
11
+ expect(channel.name).to eq(name)
11
12
  end
12
13
 
13
14
  it "creates an empty connections array" do
14
15
  channel = subject.new(name)
15
- channel.connections.should == []
16
+
17
+ expect(channel.connections).to eq([])
16
18
  end
17
19
  end
18
20
 
@@ -30,21 +32,22 @@ describe PusherFake::Channel, "#add" do
30
32
 
31
33
  it "adds the connection" do
32
34
  subject.add(connection)
33
- connections.should have_received(:push).with(connection)
35
+
36
+ expect(connections).to have_received(:push).with(connection)
34
37
  end
35
38
 
36
39
  it "successfully subscribes the connection" do
37
40
  subject.add(connection)
38
- connection.should have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
41
+
42
+ expect(connection).to have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
39
43
  end
40
44
 
41
45
  it "triggers channel occupied webhook for the first connection added" do
42
46
  subject.unstub(:connections)
43
47
 
44
- subject.add(connection)
45
- PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
46
- subject.add(connection)
47
- PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
48
+ 2.times { subject.add(connection) }
49
+
50
+ expect(PusherFake::Webhook).to have_received(:trigger).with("channel_occupied", channel: name).once
48
51
  end
49
52
  end
50
53
 
@@ -66,14 +69,16 @@ describe PusherFake::Channel, "#emit" do
66
69
 
67
70
  it "emits the event for each connection in the channel" do
68
71
  subject.emit(event, data)
69
- connection_1.should have_received(:emit).with(event, data, name)
70
- connection_2.should have_received(:emit).with(event, data, name)
72
+
73
+ expect(connection_1).to have_received(:emit).with(event, data, name)
74
+ expect(connection_2).to have_received(:emit).with(event, data, name)
71
75
  end
72
76
 
73
77
  it "ignores connection if socket_id matches the connections socket object_id" do
74
78
  subject.emit(event, data, socket_id: socket_2.object_id)
75
- connection_1.should have_received(:emit).with(event, data, name)
76
- connection_2.should have_received(:emit).never
79
+
80
+ expect(connection_1).to have_received(:emit).with(event, data, name)
81
+ expect(connection_2).to have_received(:emit).never
77
82
  end
78
83
  end
79
84
 
@@ -84,12 +89,14 @@ describe PusherFake::Channel, "#includes?" do
84
89
 
85
90
  it "returns true if the connection is in the channel" do
86
91
  subject.stubs(connections: [connection])
87
- subject.includes?(connection).should be_true
92
+
93
+ expect(subject).to be_includes(connection)
88
94
  end
89
95
 
90
96
  it "returns false if the connection is not in the channel" do
91
97
  subject.stubs(connections: [])
92
- subject.includes?(connection).should be_false
98
+
99
+ expect(subject).to_not be_includes(connection)
93
100
  end
94
101
  end
95
102
 
@@ -107,14 +114,18 @@ describe PusherFake::Channel, "#remove" do
107
114
 
108
115
  it "removes the connection from the channel" do
109
116
  subject.remove(connection_1)
110
- subject.connections.should_not include(connection_1)
117
+
118
+ expect(subject.connections).to_not include(connection_1)
111
119
  end
112
120
 
113
121
  it "triggers channel vacated webhook when all connections are removed" do
114
122
  subject.remove(connection_1)
115
- PusherFake::Webhook.should have_received(:trigger).never
123
+
124
+ expect(PusherFake::Webhook).to have_received(:trigger).never
125
+
116
126
  subject.remove(connection_2)
117
- PusherFake::Webhook.should have_received(:trigger).with("channel_vacated", channel: name).once
127
+
128
+ expect(PusherFake::Webhook).to have_received(:trigger).with("channel_vacated", channel: name).once
118
129
  end
119
130
  end
120
131
 
@@ -122,6 +133,6 @@ describe PusherFake::Channel::Public, "#subscription_data" do
122
133
  subject { PusherFake::Channel::Public.new("name") }
123
134
 
124
135
  it "returns an empty hash" do
125
- subject.subscription_data.should == {}
136
+ expect(subject.subscription_data).to eq({})
126
137
  end
127
138
  end
@@ -16,16 +16,23 @@ describe PusherFake::Channel, ".factory" do
16
16
 
17
17
  it "caches the channel" do
18
18
  PusherFake::Channel::Public.unstub(:new)
19
- subject.factory(name).should == subject.factory(name)
19
+
20
+ factory_1 = subject.factory(name)
21
+ factory_2 = subject.factory(name)
22
+
23
+ expect(factory_1).to eq(factory_2)
20
24
  end
21
25
 
22
26
  it "creates a public channel by name" do
23
27
  subject.factory(name)
24
- PusherFake::Channel::Public.should have_received(:new).with(name)
28
+
29
+ expect(PusherFake::Channel::Public).to have_received(:new).with(name)
25
30
  end
26
31
 
27
32
  it "returns the channel instance" do
28
- subject.factory(name).should == channel
33
+ factory = subject.factory(name)
34
+
35
+ expect(factory).to eq(channel)
29
36
  end
30
37
  end
31
38
 
@@ -45,16 +52,23 @@ describe PusherFake::Channel, ".factory, for a private channel" do
45
52
 
46
53
  it "caches the channel" do
47
54
  PusherFake::Channel::Private.unstub(:new)
48
- subject.factory(name).should == subject.factory(name)
55
+
56
+ factory_1 = subject.factory(name)
57
+ factory_2 = subject.factory(name)
58
+
59
+ expect(factory_1).to eq(factory_2)
49
60
  end
50
61
 
51
62
  it "creates a private channel by name" do
52
63
  subject.factory(name)
53
- PusherFake::Channel::Private.should have_received(:new).with(name)
64
+
65
+ expect(PusherFake::Channel::Private).to have_received(:new).with(name)
54
66
  end
55
67
 
56
68
  it "returns the channel instance" do
57
- subject.factory(name).should == channel
69
+ factory = subject.factory(name)
70
+
71
+ expect(factory).to eq(channel)
58
72
  end
59
73
  end
60
74
 
@@ -74,16 +88,23 @@ describe PusherFake::Channel, ".factory, for a presence channel" do
74
88
 
75
89
  it "caches the channel" do
76
90
  PusherFake::Channel::Presence.unstub(:new)
77
- subject.factory(name).should == subject.factory(name)
91
+
92
+ factory_1 = subject.factory(name)
93
+ factory_2 = subject.factory(name)
94
+
95
+ expect(factory_1).to eq(factory_2)
78
96
  end
79
97
 
80
98
  it "creates a presence channel by name" do
81
99
  subject.factory(name)
82
- PusherFake::Channel::Presence.should have_received(:new).with(name)
100
+
101
+ expect(PusherFake::Channel::Presence).to have_received(:new).with(name)
83
102
  end
84
103
 
85
104
  it "returns the channel instance" do
86
- subject.factory(name).should == channel
105
+ factory = subject.factory(name)
106
+
107
+ expect(factory).to eq(channel)
87
108
  end
88
109
  end
89
110
 
@@ -101,23 +122,29 @@ describe PusherFake::Channel, ".remove" do
101
122
 
102
123
  it "removes the connection from all channels" do
103
124
  subject.remove(connection)
104
- channel_1.should have_received(:remove).with(connection)
105
- channel_2.should have_received(:remove).with(connection)
125
+
126
+ expect(channel_1).to have_received(:remove).with(connection)
127
+ expect(channel_2).to have_received(:remove).with(connection)
106
128
  end
107
129
 
108
130
  it "deletes a channel with no connections remaining" do
109
131
  subject.remove(connection)
110
- channels.should_not have_key(:channel_1)
132
+
133
+ expect(channels).to_not have_key(:channel_1)
111
134
  end
112
135
 
113
136
  it "does not delete a channel with connections remaining" do
114
137
  subject.remove(connection)
115
- channels.should have_key(:channel_2)
138
+
139
+ expect(channels).to have_key(:channel_2)
116
140
  end
117
141
 
118
142
  it "handles channels not being defined" do
119
143
  subject.stubs(channels: nil)
120
- subject.remove(connection)
144
+
145
+ expect {
146
+ subject.remove(connection)
147
+ }.to_not raise_error
121
148
  end
122
149
  end
123
150
 
@@ -127,6 +154,7 @@ describe PusherFake::Channel, ".reset" do
127
154
  it "empties the channel cache" do
128
155
  subject.factory("example")
129
156
  subject.reset
130
- subject.channels.should == {}
157
+
158
+ expect(subject.channels).to eq({})
131
159
  end
132
160
  end
@@ -3,22 +3,30 @@ require "spec_helper"
3
3
  describe PusherFake::Configuration do
4
4
  it { should have_configuration_option(:app_id).with_default("PUSHER_APP_ID") }
5
5
  it { should have_configuration_option(:key).with_default("PUSHER_API_KEY") }
6
+ it { should have_configuration_option(:logger).with_default(STDOUT.to_io) }
6
7
  it { should have_configuration_option(:secret).with_default("PUSHER_API_SECRET") }
7
8
  it { should have_configuration_option(:socket_options).with_default({ host: "127.0.0.1", port: 8080 }) }
9
+ it { should have_configuration_option(:verbose).with_default(false) }
8
10
  it { should have_configuration_option(:web_options).with_default({ host: "127.0.0.1", port: 8081 }) }
9
11
  it { should have_configuration_option(:webhooks).with_default([]) }
10
12
  end
11
13
 
12
14
  describe PusherFake::Configuration, "#to_options" do
13
15
  it "includes the socket host as wsHost" do
14
- subject.to_options.should include(wsHost: subject.socket_options[:host])
16
+ options = subject.to_options
17
+
18
+ expect(options).to include(wsHost: subject.socket_options[:host])
15
19
  end
16
20
 
17
21
  it "includes the socket port as wsPort" do
18
- subject.to_options.should include(wsPort: subject.socket_options[:port])
22
+ options = subject.to_options
23
+
24
+ expect(options).to include(wsPort: subject.socket_options[:port])
19
25
  end
20
26
 
21
27
  it "supports passing custom options" do
22
- subject.to_options(custom: "option").should include(custom: "option")
28
+ options = subject.to_options(custom: "option")
29
+
30
+ expect(options).to include(custom: "option")
23
31
  end
24
32
  end
@@ -7,7 +7,8 @@ describe PusherFake::Connection do
7
7
 
8
8
  it "assigns the provided socket" do
9
9
  connection = subject.new(socket)
10
- connection.socket.should == socket
10
+
11
+ expect(connection.socket).to eq(socket)
11
12
  end
12
13
  end
13
14
 
@@ -24,12 +25,14 @@ describe PusherFake::Connection, "#emit" do
24
25
 
25
26
  it "sends the event to the socket as JSON" do
26
27
  subject.emit(event, data)
27
- socket.should have_received(:send).with(json)
28
+
29
+ expect(socket).to have_received(:send).with(json)
28
30
  end
29
31
 
30
32
  it "sets a channel when provided" do
31
33
  subject.emit(event, data, channel)
32
- socket.should have_received(:send).with(channel_json)
34
+
35
+ expect(socket).to have_received(:send).with(channel_json)
33
36
  end
34
37
  end
35
38
 
@@ -44,7 +47,8 @@ describe PusherFake::Connection, "#establish" do
44
47
 
45
48
  it "emits the connection established event with the socket ID" do
46
49
  subject.establish
47
- subject.should have_received(:emit)
50
+
51
+ expect(subject).to have_received(:emit)
48
52
  .with("pusher:connection_established", socket_id: socket.object_id, activity_timeout: 120)
49
53
  end
50
54
  end
@@ -65,17 +69,20 @@ describe PusherFake::Connection, "#process, with a subscribe event" do
65
69
 
66
70
  it "parses the JSON data" do
67
71
  subject.process(json)
68
- MultiJson.should have_received(:load).with(json, symbolize_keys: true)
72
+
73
+ expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
69
74
  end
70
75
 
71
76
  it "creates a channel from the event data" do
72
77
  subject.process(json)
73
- PusherFake::Channel.should have_received(:factory).with(name)
78
+
79
+ expect(PusherFake::Channel).to have_received(:factory).with(name)
74
80
  end
75
81
 
76
82
  it "attempts to add the connection to the channel" do
77
83
  subject.process(json)
78
- channel.should have_received(:add).with(subject, data)
84
+
85
+ expect(channel).to have_received(:add).with(subject, data)
79
86
  end
80
87
  end
81
88
 
@@ -94,17 +101,51 @@ describe PusherFake::Connection, "#process, with an unsubscribe event" do
94
101
 
95
102
  it "parses the JSON data" do
96
103
  subject.process(json)
97
- MultiJson.should have_received(:load).with(json, symbolize_keys: true)
104
+
105
+ expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
98
106
  end
99
107
 
100
108
  it "creates a channel from the event data" do
101
109
  subject.process(json)
102
- PusherFake::Channel.should have_received(:factory).with(name)
110
+
111
+ expect(PusherFake::Channel).to have_received(:factory).with(name)
103
112
  end
104
113
 
105
114
  it "removes the connection from the channel" do
106
115
  subject.process(json)
107
- channel.should have_received(:remove).with(subject)
116
+
117
+ expect(channel).to have_received(:remove).with(subject)
118
+ end
119
+ end
120
+
121
+ describe PusherFake::Connection, "#process, with a ping event" do
122
+ let(:json) { stub }
123
+ let(:message) { { event: "pusher:ping", data: {} } }
124
+
125
+ subject { PusherFake::Connection.new(stub) }
126
+
127
+ before do
128
+ MultiJson.stubs(load: message)
129
+ PusherFake::Channel.stubs(:factory)
130
+ subject.stubs(:emit)
131
+ end
132
+
133
+ it "parses the JSON data" do
134
+ subject.process(json)
135
+
136
+ expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
137
+ end
138
+
139
+ it "does not create a channel" do
140
+ subject.process(json)
141
+
142
+ expect(PusherFake::Channel).to have_received(:factory).never
143
+ end
144
+
145
+ it "emits a pong event" do
146
+ subject.process(json)
147
+
148
+ expect(subject).to have_received(:emit).with("pusher:pong")
108
149
  end
109
150
  end
110
151
 
@@ -125,40 +166,50 @@ describe PusherFake::Connection, "#process, with a client event" do
125
166
 
126
167
  it "parses the JSON data" do
127
168
  subject.process(json)
128
- MultiJson.should have_received(:load).with(json, symbolize_keys: true)
169
+
170
+ expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
129
171
  end
130
172
 
131
173
  it "creates a channel from the event data" do
132
174
  subject.process(json)
133
- PusherFake::Channel.should have_received(:factory).with(name)
175
+
176
+ expect(PusherFake::Channel).to have_received(:factory).with(name)
134
177
  end
135
178
 
136
179
  it "ensures the channel is private" do
137
180
  subject.process(json)
138
- channel.should have_received(:is_a?).with(PusherFake::Channel::Private)
181
+
182
+ expect(channel).to have_received(:is_a?).with(PusherFake::Channel::Private)
139
183
  end
140
184
 
141
185
  it "checks if the connection is in the channel" do
142
186
  subject.process(json)
143
- channel.should have_received(:includes?).with(subject)
187
+
188
+ expect(channel).to have_received(:includes?).with(subject)
144
189
  end
145
190
 
146
191
  it "emits the event to the channel when the connection is in the channel" do
147
192
  channel.stubs(includes?: true)
193
+
148
194
  subject.process(json)
149
- channel.should have_received(:emit).with(event, data, socket_id: subject.socket.object_id)
195
+
196
+ expect(channel).to have_received(:emit).with(event, data, socket_id: subject.socket.object_id)
150
197
  end
151
198
 
152
199
  it "does not emit the event to the channel when the channel is not private" do
153
200
  channel.stubs(includes?: true, is_a?: false)
201
+
154
202
  subject.process(json)
155
- channel.should have_received(:emit).never
203
+
204
+ expect(channel).to have_received(:emit).never
156
205
  end
157
206
 
158
207
  it "does not emit the event to the channel when the connection is not in the channel" do
159
208
  channel.stubs(includes?: false)
209
+
160
210
  subject.process(json)
161
- channel.should have_received(:emit).never
211
+
212
+ expect(channel).to have_received(:emit).never
162
213
  end
163
214
  end
164
215
 
@@ -179,16 +230,19 @@ describe PusherFake::Connection, "#process, with an unknown event" do
179
230
 
180
231
  it "parses the JSON data" do
181
232
  subject.process(json)
182
- MultiJson.should have_received(:load).with(json, symbolize_keys: true)
233
+
234
+ expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
183
235
  end
184
236
 
185
237
  it "creates a channel from the event data" do
186
238
  subject.process(json)
187
- PusherFake::Channel.should have_received(:factory).with(name)
239
+
240
+ expect(PusherFake::Channel).to have_received(:factory).with(name)
188
241
  end
189
242
 
190
243
  it "does not emit the event" do
191
244
  subject.process(json)
192
- channel.should have_received(:emit).never
245
+
246
+ expect(channel).to have_received(:emit).never
193
247
  end
194
248
  end