pusher-fake 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pusher-fake.rb +1 -1
  3. data/lib/pusher-fake/configuration.rb +2 -1
  4. data/lib/pusher-fake/server/application.rb +1 -1
  5. data/spec/features/api/channels_spec.rb +82 -0
  6. data/spec/features/api/users_spec.rb +34 -0
  7. data/spec/features/client/connect_spec.rb +9 -0
  8. data/spec/features/client/event_spec.rb +45 -0
  9. data/spec/features/client/presence_spec.rb +56 -0
  10. data/spec/features/client/subscribe_spec.rb +61 -0
  11. data/spec/features/server/event_spec.rb +120 -0
  12. data/spec/features/server/webhooks_spec.rb +64 -0
  13. data/spec/lib/pusher-fake/channel/presence_spec.rb +36 -30
  14. data/spec/lib/pusher-fake/channel/private_spec.rb +29 -25
  15. data/spec/lib/pusher-fake/channel/public_spec.rb +18 -18
  16. data/spec/lib/pusher-fake/channel_spec.rb +14 -14
  17. data/spec/lib/pusher-fake/configuration_spec.rb +6 -0
  18. data/spec/lib/pusher-fake/connection_spec.rb +38 -36
  19. data/spec/lib/pusher-fake/server/application_spec.rb +70 -70
  20. data/spec/lib/pusher-fake/server_spec.rb +42 -41
  21. data/spec/lib/pusher-fake/webhook_spec.rb +9 -7
  22. data/spec/lib/pusher_fake_spec.rb +5 -4
  23. data/spec/spec_helper.rb +3 -1
  24. data/{features → spec}/support/application.rb +0 -0
  25. data/{features/support/application/public/javascripts/vendor/pusher-2.2.2.js → spec/support/application/public/javascripts/vendor/pusher-2.2.4.js} +26 -19
  26. data/spec/support/application/views/index.erb +83 -0
  27. data/spec/support/capybara.rb +10 -0
  28. data/spec/support/coveralls.rb +0 -1
  29. data/spec/support/helpers/connect.rb +21 -0
  30. data/spec/support/helpers/event.rb +9 -0
  31. data/spec/support/helpers/subscription.rb +29 -0
  32. data/spec/support/helpers/user.rb +11 -0
  33. data/spec/support/{have_configuration_option_matcher.rb → matchers/have_configuration_option.rb} +0 -0
  34. data/spec/support/pusher-fake.rb +15 -0
  35. data/{features → spec}/support/webhooks.rb +5 -1
  36. metadata +51 -101
  37. data/features/channel.feature +0 -109
  38. data/features/channel_presence.feature +0 -27
  39. data/features/channel_subscribe.feature +0 -33
  40. data/features/channel_trigger.feature +0 -91
  41. data/features/channel_webhooks.feature +0 -40
  42. data/features/client_connect.feature +0 -8
  43. data/features/step_definitions/api_steps.rb +0 -40
  44. data/features/step_definitions/channel_steps.rb +0 -86
  45. data/features/step_definitions/client_steps.rb +0 -23
  46. data/features/step_definitions/event_steps.rb +0 -56
  47. data/features/step_definitions/navigation_steps.rb +0 -3
  48. data/features/step_definitions/presence_steps.rb +0 -6
  49. data/features/step_definitions/webhook_steps.rb +0 -21
  50. data/features/support/application/views/index.erb +0 -35
  51. data/features/support/coveralls.rb +0 -1
  52. data/features/support/environment.rb +0 -13
  53. data/features/support/pusher-fake.rb +0 -11
  54. data/features/support/timing.rb +0 -15
  55. data/features/user.feature +0 -14
@@ -2,12 +2,12 @@ require "spec_helper"
2
2
 
3
3
  describe PusherFake::Channel, ".factory" do
4
4
  let(:name) { "channel" }
5
- let(:channel) { stub }
5
+ let(:channel) { double }
6
6
 
7
7
  subject { PusherFake::Channel }
8
8
 
9
9
  before do
10
- PusherFake::Channel::Public.stubs(new: channel)
10
+ allow(PusherFake::Channel::Public).to receive(:new).and_return(channel)
11
11
  end
12
12
 
13
13
  after do
@@ -15,7 +15,7 @@ describe PusherFake::Channel, ".factory" do
15
15
  end
16
16
 
17
17
  it "caches the channel" do
18
- PusherFake::Channel::Public.unstub(:new)
18
+ allow(PusherFake::Channel::Public).to receive(:new).and_call_original
19
19
 
20
20
  factory_1 = subject.factory(name)
21
21
  factory_2 = subject.factory(name)
@@ -38,12 +38,12 @@ end
38
38
 
39
39
  describe PusherFake::Channel, ".factory, for a private channel" do
40
40
  let(:name) { "private-channel" }
41
- let(:channel) { stub }
41
+ let(:channel) { double }
42
42
 
43
43
  subject { PusherFake::Channel }
44
44
 
45
45
  before do
46
- PusherFake::Channel::Private.stubs(new: channel)
46
+ allow(PusherFake::Channel::Private).to receive(:new).and_return(channel)
47
47
  end
48
48
 
49
49
  after do
@@ -51,7 +51,7 @@ describe PusherFake::Channel, ".factory, for a private channel" do
51
51
  end
52
52
 
53
53
  it "caches the channel" do
54
- PusherFake::Channel::Private.unstub(:new)
54
+ allow(PusherFake::Channel::Private).to receive(:new).and_call_original
55
55
 
56
56
  factory_1 = subject.factory(name)
57
57
  factory_2 = subject.factory(name)
@@ -74,12 +74,12 @@ end
74
74
 
75
75
  describe PusherFake::Channel, ".factory, for a presence channel" do
76
76
  let(:name) { "presence-channel" }
77
- let(:channel) { stub }
77
+ let(:channel) { double }
78
78
 
79
79
  subject { PusherFake::Channel }
80
80
 
81
81
  before do
82
- PusherFake::Channel::Presence.stubs(new: channel)
82
+ allow(PusherFake::Channel::Presence).to receive(:new).and_return(channel)
83
83
  end
84
84
 
85
85
  after do
@@ -87,7 +87,7 @@ describe PusherFake::Channel, ".factory, for a presence channel" do
87
87
  end
88
88
 
89
89
  it "caches the channel" do
90
- PusherFake::Channel::Presence.unstub(:new)
90
+ allow(PusherFake::Channel::Presence).to receive(:new).and_call_original
91
91
 
92
92
  factory_1 = subject.factory(name)
93
93
  factory_2 = subject.factory(name)
@@ -110,14 +110,14 @@ end
110
110
 
111
111
  describe PusherFake::Channel, ".remove" do
112
112
  let(:channels) { { channel_1: channel_1, channel_2: channel_2 } }
113
- let(:channel_1) { stub(connections: stub(empty?: true), remove: nil) }
114
- let(:channel_2) { stub(connections: stub(empty?: false), remove: nil) }
115
- let(:connection) { mock }
113
+ let(:channel_1) { double(:channel, connections: double(:array, empty?: true), remove: nil) }
114
+ let(:channel_2) { double(:channel, connections: double(:array, empty?: false), remove: nil) }
115
+ let(:connection) { double }
116
116
 
117
117
  subject { PusherFake::Channel }
118
118
 
119
119
  before do
120
- subject.stubs(channels: channels)
120
+ allow(subject).to receive(:channels).and_return(channels)
121
121
  end
122
122
 
123
123
  it "removes the connection from all channels" do
@@ -140,7 +140,7 @@ describe PusherFake::Channel, ".remove" do
140
140
  end
141
141
 
142
142
  it "handles channels not being defined" do
143
- subject.stubs(channels: nil)
143
+ allow(subject).to receive(:channels).and_return(nil)
144
144
 
145
145
  expect {
146
146
  subject.remove(connection)
@@ -38,6 +38,12 @@ describe PusherFake::Configuration, "#to_options" do
38
38
  expect(options).to include(wsPort: subject.socket_options[:port])
39
39
  end
40
40
 
41
+ it "only enables the WebSocket transport" do
42
+ options = subject.to_options
43
+
44
+ expect(options).to include(enabledTransports: ["ws"])
45
+ end
46
+
41
47
  it "supports passing custom options" do
42
48
  options = subject.to_options(custom: "option")
43
49
 
@@ -1,13 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  shared_examples_for "#process" do
4
- let(:json) { stub }
4
+ let(:json) { double }
5
5
 
6
- subject { PusherFake::Connection.new(stub) }
6
+ subject { PusherFake::Connection.new(double) }
7
7
 
8
8
  before do
9
- PusherFake.stubs(:log)
10
- MultiJson.stubs(load: message)
9
+ allow(PusherFake).to receive(:log)
10
+ allow(MultiJson).to receive(:load).and_return(message)
11
11
  end
12
12
 
13
13
  it "parses the JSON data" do
@@ -24,7 +24,7 @@ shared_examples_for "#process" do
24
24
  end
25
25
 
26
26
  describe PusherFake::Connection do
27
- let(:socket) { stub }
27
+ let(:socket) { double }
28
28
 
29
29
  subject { PusherFake::Connection }
30
30
 
@@ -39,7 +39,7 @@ describe PusherFake::Connection, "#emit" do
39
39
  let(:data) { { some: "data", good: true } }
40
40
  let(:json) { MultiJson.dump(message) }
41
41
  let(:event) { "name" }
42
- let(:socket) { stub(:send) }
42
+ let(:socket) { double(:socket, send: nil) }
43
43
  let(:channel) { "channel" }
44
44
  let(:message) { { event: event, data: MultiJson.dump(data) } }
45
45
  let(:channel_json) { MultiJson.dump(message.merge(channel: channel)) }
@@ -47,7 +47,7 @@ describe PusherFake::Connection, "#emit" do
47
47
  subject { PusherFake::Connection.new(socket) }
48
48
 
49
49
  before do
50
- PusherFake.stubs(:log)
50
+ allow(PusherFake).to receive(:log)
51
51
  end
52
52
 
53
53
  it "sends the event to the socket as JSON" do
@@ -70,12 +70,12 @@ describe PusherFake::Connection, "#emit" do
70
70
  end
71
71
 
72
72
  describe PusherFake::Connection, "#establish" do
73
- let(:socket) { stub }
73
+ let(:socket) { double }
74
74
 
75
75
  subject { PusherFake::Connection.new(socket) }
76
76
 
77
77
  before do
78
- subject.stubs(:emit)
78
+ allow(subject).to receive(:emit)
79
79
  end
80
80
 
81
81
  it "emits the connection established event with the connection ID" do
@@ -88,7 +88,7 @@ end
88
88
 
89
89
  describe PusherFake::Connection, "#id" do
90
90
  let(:id) { socket.object_id.to_s }
91
- let(:socket) { stub }
91
+ let(:socket) { double }
92
92
 
93
93
  subject { PusherFake::Connection.new(socket) }
94
94
 
@@ -101,11 +101,11 @@ describe PusherFake::Connection, "#process, with a subscribe event" do
101
101
  it_should_behave_like "#process" do
102
102
  let(:data) { { channel: name, auth: "auth" } }
103
103
  let(:name) { "channel" }
104
- let(:channel) { stub(add: nil) }
104
+ let(:channel) { double(:channel, add: nil) }
105
105
  let(:message) { { event: "pusher:subscribe", data: data } }
106
106
 
107
107
  before do
108
- PusherFake::Channel.stubs(factory: channel)
108
+ allow(PusherFake::Channel).to receive(:factory).and_return(channel)
109
109
  end
110
110
 
111
111
  it "creates a channel from the event data" do
@@ -125,11 +125,11 @@ end
125
125
  describe PusherFake::Connection, "#process, with an unsubscribe event" do
126
126
  it_should_behave_like "#process" do
127
127
  let(:name) { "channel" }
128
- let(:channel) { stub(remove: nil) }
128
+ let(:channel) { double(:channel, remove: nil) }
129
129
  let(:message) { { event: "pusher:unsubscribe", channel: name } }
130
130
 
131
131
  before do
132
- PusherFake::Channel.stubs(factory: channel)
132
+ allow(PusherFake::Channel).to receive(:factory).and_return(channel)
133
133
  end
134
134
 
135
135
  it "creates a channel from the event data" do
@@ -151,13 +151,14 @@ describe PusherFake::Connection, "#process, with a ping event" do
151
151
  let(:message) { { event: "pusher:ping", data: {} } }
152
152
 
153
153
  before do
154
- subject.stubs(:emit)
154
+ allow(subject).to receive(:emit)
155
+ allow(PusherFake::Channel).to receive(:factory)
155
156
  end
156
157
 
157
158
  it "does not create a channel" do
158
159
  subject.process(json)
159
160
 
160
- expect(PusherFake::Channel).to have_received(:factory).never
161
+ expect(PusherFake::Channel).to_not have_received(:factory)
161
162
  end
162
163
 
163
164
  it "emits a pong event" do
@@ -173,12 +174,12 @@ describe PusherFake::Connection, "#process, with a client event" do
173
174
  let(:data) { {} }
174
175
  let(:name) { "channel" }
175
176
  let(:event) { "client-hello-world" }
176
- let(:channel) { stub(emit: nil, includes?: nil, is_a?: true) }
177
+ let(:channel) { double(:channel, emit: nil, includes?: nil, is_a?: true) }
177
178
  let(:message) { { event: event, data: data, channel: name } }
178
179
 
179
180
  before do
180
- subject.stubs(:trigger)
181
- PusherFake::Channel.stubs(factory: channel)
181
+ allow(subject).to receive(:trigger)
182
+ allow(PusherFake::Channel).to receive(:factory).and_return(channel)
182
183
  end
183
184
 
184
185
  it "creates a channel from the event data" do
@@ -200,7 +201,7 @@ describe PusherFake::Connection, "#process, with a client event" do
200
201
  end
201
202
 
202
203
  it "emits the event to the channel when the connection is in the channel" do
203
- channel.stubs(includes?: true)
204
+ allow(channel).to receive(:includes?).and_return(true)
204
205
 
205
206
  subject.process(json)
206
207
 
@@ -208,19 +209,20 @@ describe PusherFake::Connection, "#process, with a client event" do
208
209
  end
209
210
 
210
211
  it "does not emit the event to the channel when the channel is not private" do
211
- channel.stubs(includes?: true, is_a?: false)
212
+ allow(channel).to receive(:is_a?).and_return(false)
213
+ allow(channel).to receive(:includes?).and_return(true)
212
214
 
213
215
  subject.process(json)
214
216
 
215
- expect(channel).to have_received(:emit).never
217
+ expect(channel).to_not have_received(:emit)
216
218
  end
217
219
 
218
220
  it "does not emit the event to the channel when the connection is not in the channel" do
219
- channel.stubs(includes?: false)
221
+ allow(channel).to receive(:includes?).and_return(false)
220
222
 
221
223
  subject.process(json)
222
224
 
223
- expect(channel).to have_received(:emit).never
225
+ expect(channel).to_not have_received(:emit)
224
226
  end
225
227
  end
226
228
  end
@@ -231,20 +233,20 @@ describe PusherFake::Connection, "#process, with a client event trigger a webhoo
231
233
  let(:name) { "channel" }
232
234
  let(:event) { "client-hello-world" }
233
235
  let(:user_id) { 1 }
234
- let(:channel) { stub(name: name, emit: nil, includes?: nil) }
236
+ let(:channel) { double(:channel, name: name, emit: nil, includes?: nil) }
235
237
  let(:message) { { event: event, channel: name } }
236
238
  let(:options) { { channel: name, event: event, socket_id: subject.id } }
237
239
 
238
240
  before do
239
- channel.stubs(:trigger)
240
- channel.stubs(:includes?).with(subject).returns(true)
241
- channel.stubs(:is_a?).with(PusherFake::Channel::Private).returns(true)
242
- channel.stubs(:is_a?).with(PusherFake::Channel::Presence).returns(false)
241
+ allow(channel).to receive(:trigger)
242
+ allow(channel).to receive(:includes?).with(subject).and_return(true)
243
+ allow(channel).to receive(:is_a?).with(PusherFake::Channel::Private).and_return(true)
244
+ allow(channel).to receive(:is_a?).with(PusherFake::Channel::Presence).and_return(false)
243
245
 
244
246
  # NOTE: Hack to avoid race condition in unit tests.
245
- Thread.stubs(:new).yields
247
+ allow(Thread).to receive(:new).and_yield
246
248
 
247
- PusherFake::Channel.stubs(factory: channel)
249
+ allow(PusherFake::Channel).to receive(:factory).and_return(channel)
248
250
  end
249
251
 
250
252
  it "triggers the client event webhook" do
@@ -264,8 +266,8 @@ describe PusherFake::Connection, "#process, with a client event trigger a webhoo
264
266
  end
265
267
 
266
268
  it "includes user ID in event when on a presence channel" do
267
- channel.stubs(:is_a?).with(PusherFake::Channel::Presence).returns(true)
268
- channel.stubs(members: { subject => { user_id: user_id } })
269
+ allow(channel).to receive(:is_a?).with(PusherFake::Channel::Presence).and_return(true)
270
+ allow(channel).to receive(:members).and_return({ subject => { user_id: user_id } })
269
271
 
270
272
  subject.process(json)
271
273
 
@@ -280,11 +282,11 @@ describe PusherFake::Connection, "#process, with an unknown event" do
280
282
  let(:data) { {} }
281
283
  let(:name) { "channel" }
282
284
  let(:event) { "hello-world" }
283
- let(:channel) { stub(emit: nil) }
285
+ let(:channel) { double(:channel, emit: nil) }
284
286
  let(:message) { { event: event, data: data, channel: name } }
285
287
 
286
288
  before do
287
- PusherFake::Channel.stubs(factory: channel)
289
+ allow(PusherFake::Channel).to receive(:factory).and_return(channel)
288
290
  end
289
291
 
290
292
  it "creates a channel from the event data" do
@@ -296,7 +298,7 @@ describe PusherFake::Connection, "#process, with an unknown event" do
296
298
  it "does not emit the event" do
297
299
  subject.process(json)
298
300
 
299
- expect(channel).to have_received(:emit).never
301
+ expect(channel).to_not have_received(:emit)
300
302
  end
301
303
  end
302
304
  end
@@ -1,20 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
3
  shared_examples_for "an API request" do
4
- let(:hash) { mock }
5
- let(:string) { mock }
6
- let(:request) { stub(path: path) }
7
- let(:response) { mock }
8
- let(:environment) { mock }
4
+ let(:hash) { double }
5
+ let(:string) { double }
6
+ let(:request) { double(:request, path: path) }
7
+ let(:response) { double }
8
+ let(:environment) { double }
9
9
 
10
10
  subject { PusherFake::Server::Application }
11
11
 
12
12
  before do
13
- response.stubs(finish: response)
13
+ allow(response).to receive(:finish).and_return(response)
14
14
 
15
- MultiJson.stubs(dump: string)
16
- Rack::Request.stubs(new: request)
17
- Rack::Response.stubs(new: response)
15
+ allow(MultiJson).to receive(:dump).and_return(string)
16
+ allow(Rack::Request).to receive(:new).and_return(request)
17
+ allow(Rack::Response).to receive(:new).and_return(response)
18
18
  end
19
19
 
20
20
  it "creates a request" do
@@ -38,7 +38,7 @@ shared_examples_for "an API request" do
38
38
  it "finishes the response" do
39
39
  subject.call(environment)
40
40
 
41
- expect(response).to have_received(:finish).with()
41
+ expect(response).to have_received(:finish).with(no_args)
42
42
  end
43
43
 
44
44
  it "returns the response" do
@@ -54,7 +54,7 @@ describe PusherFake::Server::Application, ".call, for triggering events" do
54
54
  let(:path) { "/apps/#{id}/events" }
55
55
 
56
56
  before do
57
- subject.stubs(events: hash)
57
+ allow(subject).to receive(:events).and_return(hash)
58
58
  end
59
59
 
60
60
  it "emits events" do
@@ -71,7 +71,7 @@ describe PusherFake::Server::Application, ".call, for retrieving occupied channe
71
71
  let(:path) { "/apps/#{id}/channels" }
72
72
 
73
73
  before do
74
- subject.stubs(channels: hash)
74
+ allow(subject).to receive(:channels).and_return(hash)
75
75
  end
76
76
 
77
77
  it "filters the occupied channels" do
@@ -84,16 +84,16 @@ end
84
84
 
85
85
  describe PusherFake::Server::Application, ".call, with unknown path" do
86
86
  let(:path) { "/apps/fake/events" }
87
- let(:request) { stub(path: path) }
87
+ let(:request) { double(:request, path: path) }
88
88
  let(:message) { "Unknown path: #{path}" }
89
- let(:response) { mock }
90
- let(:environment) { mock }
89
+ let(:response) { double }
90
+ let(:environment) { double }
91
91
 
92
92
  before do
93
- response.stubs(finish: response)
93
+ allow(response).to receive(:finish).and_return(response)
94
94
 
95
- Rack::Request.stubs(new: request)
96
- Rack::Response.stubs(new: response)
95
+ allow(Rack::Request).to receive(:new).and_return(request)
96
+ allow(Rack::Response).to receive(:new).and_return(response)
97
97
  end
98
98
 
99
99
  subject { PusherFake::Server::Application }
@@ -113,7 +113,7 @@ describe PusherFake::Server::Application, ".call, with unknown path" do
113
113
  it "finishes the response" do
114
114
  subject.call(environment)
115
115
 
116
- expect(response).to have_received(:finish).with()
116
+ expect(response).to have_received(:finish).with(no_args)
117
117
  end
118
118
 
119
119
  it "returns the response" do
@@ -127,19 +127,19 @@ describe PusherFake::Server::Application, ".call, raising an error" do
127
127
  let(:id) { PusherFake.configuration.app_id }
128
128
  let(:path) { "/apps/#{id}/channels" }
129
129
  let(:message) { "Example error message." }
130
- let(:request) { stub(path: path) }
131
- let(:response) { mock }
132
- let(:environment) { mock }
130
+ let(:request) { double(:request, path: path) }
131
+ let(:response) { double }
132
+ let(:environment) { double }
133
133
 
134
134
  subject { PusherFake::Server::Application }
135
135
 
136
136
  before do
137
- subject.stubs(:channels).raises(message)
137
+ allow(subject).to receive(:channels).and_raise(message)
138
138
 
139
- response.stubs(finish: response)
139
+ allow(response).to receive(:finish).and_return(response)
140
140
 
141
- Rack::Request.stubs(new: request)
142
- Rack::Response.stubs(new: response)
141
+ allow(Rack::Request).to receive(:new).and_return(request)
142
+ allow(Rack::Response).to receive(:new).and_return(response)
143
143
  end
144
144
 
145
145
  it "creates a request" do
@@ -157,7 +157,7 @@ describe PusherFake::Server::Application, ".call, raising an error" do
157
157
  it "finishes the response" do
158
158
  subject.call(environment)
159
159
 
160
- expect(response).to have_received(:finish).with()
160
+ expect(response).to have_received(:finish).with(no_args)
161
161
  end
162
162
 
163
163
  it "returns the response" do
@@ -168,25 +168,25 @@ describe PusherFake::Server::Application, ".call, raising an error" do
168
168
  end
169
169
 
170
170
  describe PusherFake::Server::Application, ".events" do
171
- let(:body) { stub(read: event_json) }
171
+ let(:body) { double(:body, read: event_json) }
172
172
  let(:data) { { "example" => "data" } }
173
173
  let(:name) { "event-name" }
174
174
  let(:event) { { "channels" => channels, "name" => name, "data" => data_json, "socket_id" => socket_id } }
175
- let(:request) { stub(body: body) }
175
+ let(:request) { double(:request, body: body) }
176
176
  let(:channels) { ["channel-1", "channel-2"] }
177
- let(:channel_1) { stub(emit: true) }
178
- let(:channel_2) { stub(emit: true) }
177
+ let(:channel_1) { double(:channel, emit: true) }
178
+ let(:channel_2) { double(:channel, emit: true) }
179
179
  let(:data_json) { data.to_json }
180
- let(:socket_id) { stub }
181
- let(:event_json) { mock }
180
+ let(:socket_id) { double }
181
+ let(:event_json) { double }
182
182
 
183
183
  subject { PusherFake::Server::Application }
184
184
 
185
185
  before do
186
- MultiJson.stubs(:load).with(event_json).returns(event)
187
- MultiJson.stubs(:load).with(data_json).returns(data)
188
- PusherFake::Channel.stubs(:factory).with(channels[0]).returns(channel_1)
189
- PusherFake::Channel.stubs(:factory).with(channels[1]).returns(channel_2)
186
+ allow(MultiJson).to receive(:load).with(event_json).and_return(event)
187
+ allow(MultiJson).to receive(:load).with(data_json).and_return(data)
188
+ allow(PusherFake::Channel).to receive(:factory).with(channels[0]).and_return(channel_1)
189
+ allow(PusherFake::Channel).to receive(:factory).with(channels[1]).and_return(channel_2)
190
190
  end
191
191
 
192
192
  it "parses the request body as JSON" do
@@ -204,7 +204,7 @@ describe PusherFake::Server::Application, ".events" do
204
204
  it "handles invalid JSON for event data" do
205
205
  event["data"] = data = "fake"
206
206
 
207
- MultiJson.stubs(:load).with(data).raises(MultiJson::LoadError)
207
+ allow(MultiJson).to receive(:load).with(data).and_raise(MultiJson::LoadError)
208
208
 
209
209
  expect {
210
210
  subject.events(request)
@@ -231,13 +231,13 @@ describe PusherFake::Server::Application, ".events" do
231
231
  end
232
232
 
233
233
  describe PusherFake::Server::Application, ".channels, requesting all channels" do
234
- let(:request) { stub(params: {}) }
235
- let(:channels) { { "channel-1" => mock, "channel-2" => mock } }
234
+ let(:request) { double(:request, params: {}) }
235
+ let(:channels) { { "channel-1" => double, "channel-2" => double } }
236
236
 
237
237
  subject { PusherFake::Server::Application }
238
238
 
239
239
  before do
240
- PusherFake::Channel.stubs(channels: channels)
240
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
241
241
  end
242
242
 
243
243
  it "returns a hash of all the channels" do
@@ -249,13 +249,13 @@ end
249
249
 
250
250
  describe PusherFake::Server::Application, ".channels, requesting channels with a filter" do
251
251
  let(:params) { { "filter_by_prefix" => "public-" } }
252
- let(:request) { stub(params: params) }
253
- let(:channels) { { "public-1" => mock, "presence-1" => mock } }
252
+ let(:request) { double(:request, params: params) }
253
+ let(:channels) { { "public-1" => double, "presence-1" => double } }
254
254
 
255
255
  subject { PusherFake::Server::Application }
256
256
 
257
257
  before do
258
- PusherFake::Channel.stubs(channels: channels)
258
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
259
259
  end
260
260
 
261
261
  it "returns a hash of the channels matching the filter" do
@@ -267,14 +267,14 @@ end
267
267
 
268
268
  describe PusherFake::Server::Application, ".channels, requesting user count for channels with a filter" do
269
269
  let(:params) { { "filter_by_prefix" => "presence-", "info" => "user_count" } }
270
- let(:request) { stub(params: params) }
271
- let(:channel) { stub(connections: [mock, mock]) }
272
- let(:channels) { { "public-1" => mock, "presence-1" => channel } }
270
+ let(:request) { double(:request, params: params) }
271
+ let(:channel) { double(:channel, connections: [double, double]) }
272
+ let(:channels) { { "public-1" => double, "presence-1" => channel } }
273
273
 
274
274
  subject { PusherFake::Server::Application }
275
275
 
276
276
  before do
277
- PusherFake::Channel.stubs(channels: channels)
277
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
278
278
  end
279
279
 
280
280
  it "returns a hash of the channels matching the filter and include the user count" do
@@ -285,13 +285,13 @@ describe PusherFake::Server::Application, ".channels, requesting user count for
285
285
  end
286
286
 
287
287
  describe PusherFake::Server::Application, ".channels, requesting all channels with no channels occupied" do
288
- let(:request) { stub(params: {}) }
288
+ let(:request) { double(:request, params: {}) }
289
289
  let(:channels) { nil }
290
290
 
291
291
  subject { PusherFake::Server::Application }
292
292
 
293
293
  before do
294
- PusherFake::Channel.stubs(channels: channels)
294
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
295
295
  end
296
296
 
297
297
  it "returns a hash of no channels" do
@@ -303,7 +303,7 @@ end
303
303
 
304
304
  describe PusherFake::Server::Application, ".channels, requesting a user count on a non-presence channel" do
305
305
  let(:params) { { "filter_by_prefix" => "public-", "info" => "user_count" } }
306
- let(:request) { stub(params: params) }
306
+ let(:request) { double(:request, params: params) }
307
307
 
308
308
  subject { PusherFake::Server::Application }
309
309
 
@@ -316,14 +316,14 @@ end
316
316
 
317
317
  describe PusherFake::Server::Application, ".channel, for an occupied channel" do
318
318
  let(:name) { "public-1" }
319
- let(:request) { stub(params: {}) }
320
- let(:channel) { stub(connections: [mock]) }
319
+ let(:request) { double(:request, params: {}) }
320
+ let(:channel) { double(:channel, connections: [double]) }
321
321
  let(:channels) { { name => channel } }
322
322
 
323
323
  subject { PusherFake::Server::Application }
324
324
 
325
325
  before do
326
- PusherFake::Channel.stubs(channels: channels)
326
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
327
327
  end
328
328
 
329
329
  it "returns a hash with the occupied status" do
@@ -335,14 +335,14 @@ end
335
335
 
336
336
  describe PusherFake::Server::Application, ".channel, for an unoccupied channel" do
337
337
  let(:name) { "public-1" }
338
- let(:request) { stub(params: {}) }
339
- let(:channel) { stub(connections: []) }
338
+ let(:request) { double(:request, params: {}) }
339
+ let(:channel) { double(:channel, connections: []) }
340
340
  let(:channels) { { name => channel } }
341
341
 
342
342
  subject { PusherFake::Server::Application }
343
343
 
344
344
  before do
345
- PusherFake::Channel.stubs(channels: channels)
345
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
346
346
  end
347
347
 
348
348
  it "returns a hash with the occupied status" do
@@ -353,13 +353,13 @@ describe PusherFake::Server::Application, ".channel, for an unoccupied channel"
353
353
  end
354
354
 
355
355
  describe PusherFake::Server::Application, ".channel, for an unknown channel" do
356
- let(:request) { stub(params: {}) }
356
+ let(:request) { double(:request, params: {}) }
357
357
  let(:channels) { {} }
358
358
 
359
359
  subject { PusherFake::Server::Application }
360
360
 
361
361
  before do
362
- PusherFake::Channel.stubs(channels: channels)
362
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
363
363
  end
364
364
 
365
365
  it "returns a hash with the occupied status" do
@@ -372,14 +372,14 @@ end
372
372
  describe PusherFake::Server::Application, ".channel, request user count for a presence channel" do
373
373
  let(:name) { "presence-1" }
374
374
  let(:params) { { "info" => "user_count" } }
375
- let(:request) { stub(params: params) }
376
- let(:channel) { stub(connections: [mock, mock]) }
375
+ let(:request) { double(:request, params: params) }
376
+ let(:channel) { double(:channel, connections: [double, double]) }
377
377
  let(:channels) { { name => channel } }
378
378
 
379
379
  subject { PusherFake::Server::Application }
380
380
 
381
381
  before do
382
- PusherFake::Channel.stubs(channels: channels)
382
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
383
383
  end
384
384
 
385
385
  it "returns a hash with the occupied status" do
@@ -391,7 +391,7 @@ end
391
391
 
392
392
  describe PusherFake::Server::Application, ".channel, requesting a user count on a non-presence channel" do
393
393
  let(:params) { { "info" => "user_count" } }
394
- let(:request) { stub(params: params) }
394
+ let(:request) { double(:request, params: params) }
395
395
 
396
396
  subject { PusherFake::Server::Application }
397
397
 
@@ -404,15 +404,15 @@ end
404
404
 
405
405
  describe PusherFake::Server::Application, ".users, for an occupied channel" do
406
406
  let(:name) { "public-1" }
407
- let(:user_1) { stub(id: "1") }
408
- let(:user_2) { stub(id: "2") }
409
- let(:channel) { stub(connections: [user_1, user_2]) }
407
+ let(:user_1) { double(:user, id: "1") }
408
+ let(:user_2) { double(:user, id: "2") }
409
+ let(:channel) { double(:channel, connections: [user_1, user_2]) }
410
410
  let(:channels) { { name => channel } }
411
411
 
412
412
  subject { PusherFake::Server::Application }
413
413
 
414
414
  before do
415
- PusherFake::Channel.stubs(channels: channels)
415
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
416
416
  end
417
417
 
418
418
  it "returns a hash with the occupied status" do
@@ -427,13 +427,13 @@ end
427
427
 
428
428
  describe PusherFake::Server::Application, ".users, for an empty channel" do
429
429
  let(:name) { "public-1" }
430
- let(:channel) { stub(connections: []) }
430
+ let(:channel) { double(:channel, connections: []) }
431
431
  let(:channels) { { name => channel } }
432
432
 
433
433
  subject { PusherFake::Server::Application }
434
434
 
435
435
  before do
436
- PusherFake::Channel.stubs(channels: channels)
436
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
437
437
  end
438
438
 
439
439
  it "returns a hash with the occupied status" do
@@ -449,7 +449,7 @@ describe PusherFake::Server::Application, ".users, for an unknown channel" do
449
449
  subject { PusherFake::Server::Application }
450
450
 
451
451
  before do
452
- PusherFake::Channel.stubs(channels: channels)
452
+ allow(PusherFake::Channel).to receive(:channels).and_return(channels)
453
453
  end
454
454
 
455
455
  it "returns a hash with the occupied status" do