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
@@ -4,55 +4,56 @@ describe PusherFake::Server, ".start" do
4
4
  subject { PusherFake::Server }
5
5
 
6
6
  before do
7
- subject.stubs(start_web_server: nil, start_socket_server: nil)
8
- EventMachine.stubs(run: nil)
7
+ allow(subject).to receive(:start_web_server).and_return(nil)
8
+ allow(subject).to receive(:start_socket_server).and_return(nil)
9
+ allow(EventMachine).to receive(:run).and_return(nil)
9
10
  end
10
11
 
11
12
  it "runs the event loop" do
12
13
  subject.start
13
14
 
14
- expect(EventMachine).to have_received(:run).with()
15
+ expect(EventMachine).to have_received(:run).with(no_args)
15
16
  end
16
17
 
17
18
  it "starts the socket web server when run yields" do
18
19
  subject.start
19
20
 
20
- expect(subject).to have_received(:start_web_server).never
21
+ expect(subject).to_not have_received(:start_web_server)
21
22
 
22
- EventMachine.stubs(:run).yields
23
+ allow(EventMachine).to receive(:run).and_yield
23
24
 
24
25
  subject.start
25
26
 
26
- expect(subject).to have_received(:start_web_server).with()
27
+ expect(subject).to have_received(:start_web_server).with(no_args)
27
28
  end
28
29
 
29
30
  it "starts the socket server when run yields" do
30
31
  subject.start
31
32
 
32
- expect(subject).to have_received(:start_socket_server).never
33
+ expect(subject).to_not have_received(:start_socket_server)
33
34
 
34
- EventMachine.stubs(:run).yields
35
+ allow(EventMachine).to receive(:run).and_yield
35
36
 
36
37
  subject.start
37
38
 
38
- expect(subject).to have_received(:start_socket_server).with()
39
+ expect(subject).to have_received(:start_socket_server).with(no_args)
39
40
  end
40
41
  end
41
42
 
42
43
  describe PusherFake::Server, ".start_socket_server" do
43
- let(:data) { stub }
44
- let(:socket) { stub(onopen: nil, onmessage: nil, onclose: nil) }
44
+ let(:data) { double }
45
+ let(:socket) { double(:socket, onopen: nil, onmessage: nil, onclose: nil) }
45
46
  let(:options) { configuration.socket_options }
46
- let(:connection) { stub(establish: nil, process: nil) }
47
- let(:configuration) { stub(socket_options: { host: "192.168.0.1", port: 8080 }) }
47
+ let(:connection) { double(:connection, establish: nil, process: nil) }
48
+ let(:configuration) { double(:configuration, socket_options: { host: "192.168.0.1", port: 8080 }) }
48
49
 
49
50
  subject { PusherFake::Server }
50
51
 
51
52
  before do
52
- PusherFake.stubs(configuration: configuration)
53
- PusherFake::Channel.stubs(:remove)
54
- PusherFake::Connection.stubs(new: connection)
55
- EventMachine::WebSocket.stubs(:start).yields(socket)
53
+ allow(PusherFake).to receive(:configuration).and_return(configuration)
54
+ allow(PusherFake::Channel).to receive(:remove)
55
+ allow(PusherFake::Connection).to receive(:new).and_return(connection)
56
+ allow(EventMachine::WebSocket).to receive(:start).and_yield(socket)
56
57
  end
57
58
 
58
59
  it "creates a WebSocket server" do
@@ -64,15 +65,15 @@ describe PusherFake::Server, ".start_socket_server" do
64
65
  it "defines an open callback on the socket" do
65
66
  subject.start_socket_server
66
67
 
67
- expect(socket).to have_received(:onopen).with()
68
+ expect(socket).to have_received(:onopen).with(no_args)
68
69
  end
69
70
 
70
71
  it "creates a connection with the provided socket when onopen yields" do
71
72
  subject.start_socket_server
72
73
 
73
- expect(PusherFake::Connection).to have_received(:new).never
74
+ expect(PusherFake::Connection).to_not have_received(:new)
74
75
 
75
- socket.stubs(:onopen).yields
76
+ allow(socket).to receive(:onopen).and_yield
76
77
 
77
78
  subject.start_socket_server
78
79
 
@@ -82,35 +83,35 @@ describe PusherFake::Server, ".start_socket_server" do
82
83
  it "establishes the connection when onopen yields" do
83
84
  subject.start_socket_server
84
85
 
85
- expect(connection).to have_received(:establish).never
86
+ expect(connection).to_not have_received(:establish)
86
87
 
87
- socket.stubs(:onopen).yields
88
+ allow(socket).to receive(:onopen).and_yield
88
89
 
89
90
  subject.start_socket_server
90
91
 
91
- expect(connection).to have_received(:establish).with()
92
+ expect(connection).to have_received(:establish).with(no_args)
92
93
  end
93
94
 
94
95
  it "defines a message callback on the socket when onopen yields" do
95
96
  subject.start_socket_server
96
97
 
97
- expect(socket).to have_received(:onmessage).never
98
+ expect(socket).to_not have_received(:onmessage)
98
99
 
99
- socket.stubs(:onopen).yields
100
+ allow(socket).to receive(:onopen).and_yield
100
101
 
101
102
  subject.start_socket_server
102
103
 
103
- expect(socket).to have_received(:onmessage).with()
104
+ expect(socket).to have_received(:onmessage).with(no_args)
104
105
  end
105
106
 
106
107
  it "triggers process on the connection when onmessage yields" do
107
- socket.stubs(:onopen).yields
108
+ allow(socket).to receive(:onopen).and_yield
108
109
 
109
110
  subject.start_socket_server
110
111
 
111
- expect(connection).to have_received(:process).never
112
+ expect(connection).to_not have_received(:process)
112
113
 
113
- socket.stubs(:onmessage).yields(data)
114
+ allow(socket).to receive(:onmessage).and_yield(data)
114
115
 
115
116
  subject.start_socket_server
116
117
 
@@ -120,23 +121,23 @@ describe PusherFake::Server, ".start_socket_server" do
120
121
  it "defines a close callback on the socket when onopen yields" do
121
122
  subject.start_socket_server
122
123
 
123
- expect(socket).to have_received(:onclose).never
124
+ expect(socket).to_not have_received(:onclose)
124
125
 
125
- socket.stubs(:onopen).yields
126
+ allow(socket).to receive(:onopen).and_yield
126
127
 
127
128
  subject.start_socket_server
128
129
 
129
- expect(socket).to have_received(:onclose).with()
130
+ expect(socket).to have_received(:onclose).with(no_args)
130
131
  end
131
132
 
132
133
  it "removes the connection from all channels when onclose yields" do
133
- socket.stubs(:onopen).yields
134
+ allow(socket).to receive(:onopen).and_yield
134
135
 
135
136
  subject.start_socket_server
136
137
 
137
- expect(PusherFake::Channel).to have_received(:remove).never
138
+ expect(PusherFake::Channel).to_not have_received(:remove)
138
139
 
139
- socket.stubs(:onclose).yields
140
+ allow(socket).to receive(:onclose).and_yield
140
141
 
141
142
  subject.start_socket_server
142
143
 
@@ -147,15 +148,15 @@ end
147
148
  describe PusherFake::Server, ".start_web_server" do
148
149
  let(:host) { "192.168.0.1" }
149
150
  let(:port) { 8081 }
150
- let(:server) { stub(:start! => true, :ssl= => true) }
151
- let(:configuration) { stub(web_options: { host: host, port: port, ssl: true }) }
151
+ let(:server) { double(:server, :start! => true, :ssl= => true) }
152
+ let(:configuration) { double(:configuration, web_options: { host: host, port: port, ssl: true }) }
152
153
 
153
154
  subject { PusherFake::Server }
154
155
 
155
156
  before do
156
- Thin::Server.stubs(new: server)
157
- Thin::Logging.stubs(:silent=)
158
- PusherFake.stubs(configuration: configuration)
157
+ allow(Thin::Server).to receive(:new).and_return(server)
158
+ allow(Thin::Logging).to receive(:silent=)
159
+ allow(PusherFake).to receive(:configuration).and_return(configuration)
159
160
  end
160
161
 
161
162
  it "silences the logging" do
@@ -179,6 +180,6 @@ describe PusherFake::Server, ".start_web_server" do
179
180
  it "starts the web server" do
180
181
  subject.start_web_server
181
182
 
182
- expect(server).to have_received(:start!).with()
183
+ expect(server).to have_received(:start!).with(no_args)
183
184
  end
184
185
  end
@@ -4,25 +4,27 @@ describe PusherFake::Webhook, ".trigger" do
4
4
  subject { PusherFake::Webhook }
5
5
 
6
6
  let(:data) { { channel: "name" } }
7
- let(:http) { stub(post: true) }
7
+ let(:http) { double(:http, post: true) }
8
8
  let(:name) { "channel_occupied" }
9
+ let(:digest) { double(:digest) }
9
10
  let(:payload) { MultiJson.dump({ events: [data.merge(name: name)], time_ms: Time.now.to_i }) }
10
11
  let(:webhooks) { ["url"] }
11
12
  let(:signature) { "signature" }
12
- let(:configuration) { stub(key: "key", secret: "secret", webhooks: webhooks) }
13
+ let(:configuration) { double(:configuration, key: "key", secret: "secret", webhooks: webhooks) }
13
14
 
14
15
  before do
15
- OpenSSL::HMAC.stubs(hexdigest: signature)
16
- EventMachine::HttpRequest.stubs(new: http)
17
- PusherFake.stubs(:log)
18
- PusherFake.stubs(configuration: configuration)
16
+ allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
17
+ allow(OpenSSL::Digest::SHA256).to receive(:new).and_return(digest)
18
+ allow(EventMachine::HttpRequest).to receive(:new).and_return(http)
19
+ allow(PusherFake).to receive(:log)
20
+ allow(PusherFake).to receive(:configuration).and_return(configuration)
19
21
  end
20
22
 
21
23
  it "generates a signature" do
22
24
  subject.trigger(name, data)
23
25
 
24
26
  expect(OpenSSL::HMAC).to have_received(:hexdigest)
25
- .with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, payload)
27
+ .with(digest, configuration.secret, payload)
26
28
  end
27
29
 
28
30
  it "creates a HTTP request for each webhook URL" do
@@ -11,13 +11,14 @@ describe PusherFake, ".configure" do
11
11
  end
12
12
 
13
13
  describe PusherFake, ".configuration" do
14
- let(:configuration) { mock }
14
+ let(:configuration) { double }
15
15
 
16
16
  subject { PusherFake }
17
17
 
18
18
  before do
19
- PusherFake::Configuration.stubs(new: configuration)
20
19
  PusherFake.instance_variable_set("@configuration", nil)
20
+
21
+ allow(PusherFake::Configuration).to receive(:new).and_return(configuration)
21
22
  end
22
23
 
23
24
  after do
@@ -63,7 +64,7 @@ describe PusherFake, ".javascript" do
63
64
  end
64
65
 
65
66
  describe PusherFake, ".log" do
66
- let(:logger) { stub(:<< => "") }
67
+ let(:logger) { double(:logger, :<< => "") }
67
68
  let(:message) { "Hello world." }
68
69
  let(:configuration) { subject.configuration }
69
70
 
@@ -86,6 +87,6 @@ describe PusherFake, ".log" do
86
87
 
87
88
  subject.log(message)
88
89
 
89
- expect(logger).to have_received(:<<).never
90
+ expect(logger).to_not have_received(:<<)
90
91
  end
91
92
  end
@@ -7,8 +7,10 @@ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
7
7
  end
8
8
 
9
9
  RSpec.configure do |config|
10
- config.mock_with :mocha
11
10
  config.expect_with :rspec do |rspec|
12
11
  rspec.syntax = :expect
13
12
  end
13
+
14
+ # Raise errors for any deprecations.
15
+ config.raise_errors_for_deprecations!
14
16
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v2.2.2
2
+ * Pusher JavaScript Library v2.2.4
3
3
  * http://pusher.com/
4
4
  *
5
5
  * Copyright 2014, Pusher
@@ -626,7 +626,7 @@
626
626
  }).call(this);
627
627
 
628
628
  ;(function() {
629
- Pusher.VERSION = '2.2.2';
629
+ Pusher.VERSION = '2.2.4';
630
630
  Pusher.PROTOCOL = 7;
631
631
 
632
632
  // DEPRECATED: WS connection parameters
@@ -678,7 +678,8 @@
678
678
  }]],
679
679
  [":def", "sockjs_options", {
680
680
  hostUnencrypted: config.httpHost + ":" + config.httpPort,
681
- hostEncrypted: config.httpHost + ":" + config.httpsPort
681
+ hostEncrypted: config.httpHost + ":" + config.httpsPort,
682
+ httpPath: config.httpPath
682
683
  }],
683
684
  [":def", "timeouts", {
684
685
  loop: true,
@@ -1086,7 +1087,7 @@
1086
1087
  * @param {String} name
1087
1088
  * @param {Function} callback
1088
1089
  */
1089
- prototype.load = function(name, callback) {
1090
+ prototype.load = function(name, options, callback) {
1090
1091
  var self = this;
1091
1092
 
1092
1093
  if (self.loading[name] && self.loading[name].length > 0) {
@@ -1094,7 +1095,7 @@
1094
1095
  } else {
1095
1096
  self.loading[name] = [callback];
1096
1097
 
1097
- var request = new Pusher.ScriptRequest(self.getPath(name));
1098
+ var request = new Pusher.ScriptRequest(self.getPath(name, options));
1098
1099
  var receiver = self.receivers.create(function(error) {
1099
1100
  self.receivers.remove(receiver);
1100
1101
 
@@ -1176,7 +1177,7 @@
1176
1177
  }
1177
1178
 
1178
1179
  if (!window.JSON) {
1179
- Pusher.Dependencies.load("json2", initializeOnDocumentBody);
1180
+ Pusher.Dependencies.load("json2", {}, initializeOnDocumentBody);
1180
1181
  } else {
1181
1182
  initializeOnDocumentBody();
1182
1183
  }
@@ -2078,25 +2079,29 @@
2078
2079
  }));
2079
2080
 
2080
2081
  if (self.hooks.beforeInitialize) {
2081
- self.hooks.beforeInitialize();
2082
+ self.hooks.beforeInitialize.call(self);
2082
2083
  }
2083
2084
 
2084
2085
  if (self.hooks.isInitialized()) {
2085
2086
  self.changeState("initialized");
2086
2087
  } else if (self.hooks.file) {
2087
2088
  self.changeState("initializing");
2088
- Pusher.Dependencies.load(self.hooks.file, function(error, callback) {
2089
- if (self.hooks.isInitialized()) {
2090
- self.changeState("initialized");
2091
- callback(true);
2092
- } else {
2093
- if (error) {
2094
- self.onError(error);
2089
+ Pusher.Dependencies.load(
2090
+ self.hooks.file,
2091
+ { encrypted: self.options.encrypted },
2092
+ function(error, callback) {
2093
+ if (self.hooks.isInitialized()) {
2094
+ self.changeState("initialized");
2095
+ callback(true);
2096
+ } else {
2097
+ if (error) {
2098
+ self.onError(error);
2099
+ }
2100
+ self.onClose();
2101
+ callback(false);
2095
2102
  }
2096
- self.onClose();
2097
- callback(false);
2098
2103
  }
2099
- });
2104
+ );
2100
2105
  } else {
2101
2106
  self.onClose();
2102
2107
  }
@@ -2366,7 +2371,8 @@
2366
2371
  if (window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR === undefined) {
2367
2372
  window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;
2368
2373
  }
2369
- window.WEB_SOCKET_SWF_LOCATION = Pusher.Dependencies.getRoot() +
2374
+ window.WEB_SOCKET_SWF_LOCATION =
2375
+ Pusher.Dependencies.getRoot({ encrypted: this.options.encrypted }) +
2370
2376
  "/WebSocketMain.swf";
2371
2377
  },
2372
2378
  isInitialized: function() {
@@ -3918,7 +3924,7 @@
3918
3924
 
3919
3925
  Pusher.Channel.Authorizer.prototype = {
3920
3926
  composeQuery: function(socketId) {
3921
- var query = '&socket_id=' + encodeURIComponent(socketId) +
3927
+ var query = 'socket_id=' + encodeURIComponent(socketId) +
3922
3928
  '&channel_name=' + encodeURIComponent(this.channel.name);
3923
3929
 
3924
3930
  for(var i in this.authOptions.params) {
@@ -3999,6 +4005,7 @@
3999
4005
  script.src = this.options.authEndpoint +
4000
4006
  '?callback=' +
4001
4007
  encodeURIComponent(callback_name) +
4008
+ '&' +
4002
4009
  this.composeQuery(socketId);
4003
4010
 
4004
4011
  var head = document.getElementsByTagName("head")[0] || document.documentElement;
@@ -0,0 +1,83 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PusherFake Test Application</title>
5
+ </head>
6
+ <body>
7
+
8
+ <section>
9
+ <header>
10
+ <h1>Client disconnected.</h1>
11
+ </header>
12
+
13
+ <ul></ul>
14
+ </section>
15
+
16
+ <script src="/javascripts/vendor/pusher-2.2.4.js"></script>
17
+ <script>
18
+ Pusher.instance = <%= PusherFake.javascript %>;
19
+ Pusher.instance.connection.bind("state_change", function(states) {
20
+ var header = document.querySelector("h1");
21
+
22
+ header.innerText = "Client " + states.current + ".";
23
+ });
24
+
25
+ var Helpers = {
26
+ log: function(text, attributes) {
27
+ var list = document.querySelector("ul"),
28
+ element = document.createElement("li");
29
+
30
+ element.innerText = text;
31
+
32
+ for (var name in attributes) {
33
+ element.setAttribute(name, attributes[name]);
34
+ }
35
+
36
+ list.appendChild(element);
37
+ },
38
+
39
+ subscribe: function(name) {
40
+ Pusher.instance.subscribe(name)
41
+ .bind("pusher:subscription_succeeded", function(client) {
42
+ Helpers.log("Subscribed to " + name + ".");
43
+
44
+ for (var id in client.members) {
45
+ Helpers.log(client.members[id].name, {
46
+ "id" : "client-" + id,
47
+ "class" : "channel-" + name
48
+ });
49
+ }
50
+ })
51
+ .bind("pusher:member_added", function(client) {
52
+ Helpers.log(client.info.name, {
53
+ "id" : "client-" + client.id,
54
+ "class" : "channel-" + name
55
+ });
56
+ })
57
+ .bind("pusher:member_removed", function(client) {
58
+ var list = document.querySelector("ul"),
59
+ item = list.querySelector("#client-" + client.id);
60
+
61
+ list.removeChild(item);
62
+ })
63
+ .bind_all(function(event, message) {
64
+ Helpers.log("Channel " + name + " received " + event + " event.");
65
+ });
66
+ },
67
+
68
+ trigger: function(channel, event) {
69
+ var channel = Pusher.instance.channel(channel);
70
+
71
+ channel.trigger(event, {});
72
+ },
73
+
74
+ unsubscribe: function(name) {
75
+ Pusher.instance.unsubscribe(name)
76
+
77
+ Helpers.log("Unsubscribed from " + name + ".");
78
+ }
79
+ };
80
+ </script>
81
+
82
+ </body>
83
+ </html>