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.
- checksums.yaml +4 -4
- data/lib/pusher-fake.rb +1 -1
- data/lib/pusher-fake/configuration.rb +2 -1
- data/lib/pusher-fake/server/application.rb +1 -1
- data/spec/features/api/channels_spec.rb +82 -0
- data/spec/features/api/users_spec.rb +34 -0
- data/spec/features/client/connect_spec.rb +9 -0
- data/spec/features/client/event_spec.rb +45 -0
- data/spec/features/client/presence_spec.rb +56 -0
- data/spec/features/client/subscribe_spec.rb +61 -0
- data/spec/features/server/event_spec.rb +120 -0
- data/spec/features/server/webhooks_spec.rb +64 -0
- data/spec/lib/pusher-fake/channel/presence_spec.rb +36 -30
- data/spec/lib/pusher-fake/channel/private_spec.rb +29 -25
- data/spec/lib/pusher-fake/channel/public_spec.rb +18 -18
- data/spec/lib/pusher-fake/channel_spec.rb +14 -14
- data/spec/lib/pusher-fake/configuration_spec.rb +6 -0
- data/spec/lib/pusher-fake/connection_spec.rb +38 -36
- data/spec/lib/pusher-fake/server/application_spec.rb +70 -70
- data/spec/lib/pusher-fake/server_spec.rb +42 -41
- data/spec/lib/pusher-fake/webhook_spec.rb +9 -7
- data/spec/lib/pusher_fake_spec.rb +5 -4
- data/spec/spec_helper.rb +3 -1
- data/{features → spec}/support/application.rb +0 -0
- 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
- data/spec/support/application/views/index.erb +83 -0
- data/spec/support/capybara.rb +10 -0
- data/spec/support/coveralls.rb +0 -1
- data/spec/support/helpers/connect.rb +21 -0
- data/spec/support/helpers/event.rb +9 -0
- data/spec/support/helpers/subscription.rb +29 -0
- data/spec/support/helpers/user.rb +11 -0
- data/spec/support/{have_configuration_option_matcher.rb → matchers/have_configuration_option.rb} +0 -0
- data/spec/support/pusher-fake.rb +15 -0
- data/{features → spec}/support/webhooks.rb +5 -1
- metadata +51 -101
- data/features/channel.feature +0 -109
- data/features/channel_presence.feature +0 -27
- data/features/channel_subscribe.feature +0 -33
- data/features/channel_trigger.feature +0 -91
- data/features/channel_webhooks.feature +0 -40
- data/features/client_connect.feature +0 -8
- data/features/step_definitions/api_steps.rb +0 -40
- data/features/step_definitions/channel_steps.rb +0 -86
- data/features/step_definitions/client_steps.rb +0 -23
- data/features/step_definitions/event_steps.rb +0 -56
- data/features/step_definitions/navigation_steps.rb +0 -3
- data/features/step_definitions/presence_steps.rb +0 -6
- data/features/step_definitions/webhook_steps.rb +0 -21
- data/features/support/application/views/index.erb +0 -35
- data/features/support/coveralls.rb +0 -1
- data/features/support/environment.rb +0 -13
- data/features/support/pusher-fake.rb +0 -11
- data/features/support/timing.rb +0 -15
- data/features/user.feature +0 -14
@@ -1,27 +0,0 @@
|
|
1
|
-
@javascript
|
2
|
-
Feature: Client on a presence channel
|
3
|
-
|
4
|
-
Background:
|
5
|
-
Given I am connected
|
6
|
-
|
7
|
-
Scenario: Client subscribes to a presence channel
|
8
|
-
When I subscribe to the "presence-game-1" channel with presence events
|
9
|
-
Then I should see 1 client
|
10
|
-
When Bob is connected
|
11
|
-
Then I should see 1 client
|
12
|
-
When Bob is subscribed to the "presence-game-1" channel
|
13
|
-
Then I should see 2 clients
|
14
|
-
|
15
|
-
Scenario: Client unsubscribes from a presence channel, with other clients
|
16
|
-
Given Bob is connected
|
17
|
-
And Bob is subscribed to the "presence-game-1" channel
|
18
|
-
When I subscribe to the "presence-game-1" channel with presence events
|
19
|
-
Then I should see 2 clients
|
20
|
-
When Bob unsubscribes from the "presence-game-1" channel
|
21
|
-
Then I should see 1 client
|
22
|
-
|
23
|
-
Scenario: Subscribing client should receive User info
|
24
|
-
Given Bob is connected
|
25
|
-
And Bob is subscribed to the "presence-game-1" channel
|
26
|
-
When I subscribe to the "presence-game-1" channel with presence events
|
27
|
-
Then I should see 2 clients with the name "Alan Turing"
|
@@ -1,33 +0,0 @@
|
|
1
|
-
@javascript
|
2
|
-
Feature: Client subscribing to a channel
|
3
|
-
|
4
|
-
Background:
|
5
|
-
Given I am connected
|
6
|
-
|
7
|
-
Scenario: Client subscribes to a channel
|
8
|
-
When I subscribe to the "chat-message" channel
|
9
|
-
Then I should be subscribed to the "chat-message" channel
|
10
|
-
|
11
|
-
Scenario: Client subscribes to multiple channels
|
12
|
-
When I subscribe to the "chat-enter" channel
|
13
|
-
And I subscribe to the "chat-exit" channel
|
14
|
-
Then I should be subscribed to the "chat-enter" channel
|
15
|
-
And I should be subscribed to the "chat-exit" channel
|
16
|
-
|
17
|
-
Scenario: Client subscribes to a private channel
|
18
|
-
When I subscribe to the "private-message-bob" channel
|
19
|
-
Then I should be subscribed to the "private-message-bob" channel
|
20
|
-
|
21
|
-
Scenario: Client unsuccessfully subscribes to a private channel
|
22
|
-
Given I change my socket ID
|
23
|
-
When I subscribe to the "private-message-bob" channel
|
24
|
-
Then I should not be subscribed to the "private-message-bob" channel
|
25
|
-
|
26
|
-
Scenario: Client subscribes to a presence channel
|
27
|
-
When I subscribe to the "presence-game-1" channel
|
28
|
-
Then I should be subscribed to the "presence-game-1" channel
|
29
|
-
|
30
|
-
Scenario: Client unsuccessfully subscribes to a presence channel
|
31
|
-
Given I change my socket ID
|
32
|
-
When I subscribe to the "presence-game-1" channel
|
33
|
-
Then I should not be subscribed to the "presence-game-1" channel
|
@@ -1,91 +0,0 @@
|
|
1
|
-
@javascript
|
2
|
-
Feature: Triggering events on a channel
|
3
|
-
|
4
|
-
Background:
|
5
|
-
Given I am connected
|
6
|
-
And Bob is connected
|
7
|
-
|
8
|
-
Scenario: Server triggers an event on a subscribed public channel
|
9
|
-
Given I am subscribed to the "chat" channel
|
10
|
-
And Bob is subscribed to the "chat" channel
|
11
|
-
When a "message" event is triggered on the "chat" channel
|
12
|
-
Then I should receive a "message" event on the "chat" channel
|
13
|
-
And Bob should receive a "message" event on the "chat" channel
|
14
|
-
|
15
|
-
Scenario: Server triggers an event on a previously subscribed public channel
|
16
|
-
Given I am subscribed to the "chat" channel
|
17
|
-
And Bob is subscribed to the "chat" channel
|
18
|
-
And I unsubscribe from the "chat" channel
|
19
|
-
When a "message" event is triggered on the "chat" channel
|
20
|
-
Then I should not receive a "message" event on the "chat" channel
|
21
|
-
And Bob should receive a "message" event on the "chat" channel
|
22
|
-
|
23
|
-
Scenario: Server triggers an event on an unsubscribed public channel
|
24
|
-
When a "message" event is triggered on the "chat" channel
|
25
|
-
Then I should not receive a "message" event on the "chat" channel
|
26
|
-
And Bob should not receive a "message" event on the "chat" channel
|
27
|
-
|
28
|
-
Scenario: Server triggers an event on a subscribed private channel
|
29
|
-
Given I am subscribed to the "private-chat" channel
|
30
|
-
And Bob is subscribed to the "private-chat" channel
|
31
|
-
When a "message" event is triggered on the "private-chat" channel
|
32
|
-
Then I should receive a "message" event on the "private-chat" channel
|
33
|
-
And Bob should receive a "message" event on the "private-chat" channel
|
34
|
-
|
35
|
-
Scenario: Server triggers an event on a previously subscribed private channel
|
36
|
-
Given I am subscribed to the "private-chat" channel
|
37
|
-
And Bob is subscribed to the "private-chat" channel
|
38
|
-
And I unsubscribe from the "private-chat" channel
|
39
|
-
When a "message" event is triggered on the "private-chat" channel
|
40
|
-
Then I should not receive a "message" event on the "private-chat" channel
|
41
|
-
And Bob should receive a "message" event on the "private-chat" channel
|
42
|
-
|
43
|
-
Scenario: Server triggers an event on an unsubscribed private channel
|
44
|
-
When a "message" event is triggered on the "private-chat" channel
|
45
|
-
Then I should not receive a "message" event on the "private-chat" channel
|
46
|
-
And Bob should not receive a "message" event on the "private-chat" channel
|
47
|
-
|
48
|
-
Scenario: Client triggers a client event on a subscribed private channel
|
49
|
-
Given I am subscribed to the "private-chat" channel
|
50
|
-
And Bob is subscribed to the "private-chat" channel
|
51
|
-
When I trigger the "client-message" event on the "private-chat" channel
|
52
|
-
Then I should not receive a "client-message" event on the "private-chat" channel
|
53
|
-
And Bob should receive a "client-message" event on the "private-chat" channel
|
54
|
-
|
55
|
-
Scenario: Client triggers a client event on a previously subscribed private channel
|
56
|
-
Given I am subscribed to the "private-chat" channel
|
57
|
-
And Bob is subscribed to the "private-chat" channel
|
58
|
-
And I unsubscribe from the "private-chat" channel
|
59
|
-
When I manually trigger the "client-message" event on the "private-chat" channel
|
60
|
-
Then I should not receive a "client-message" event on the "private-chat" channel
|
61
|
-
And Bob should not receive a "client-message" event on the "private-chat" channel
|
62
|
-
|
63
|
-
Scenario: Client triggers a client event on an unsubscribed private channel
|
64
|
-
Given Bob is subscribed to the "private-chat" channel
|
65
|
-
When I manually trigger the "client-message" event on the "private-chat" channel
|
66
|
-
Then I should not receive a "client-message" event on the "private-chat" channel
|
67
|
-
And Bob should not receive a "client-message" event on the "private-chat" channel
|
68
|
-
|
69
|
-
Scenario: Client triggers a client event on a subscribed public channel
|
70
|
-
Given I am subscribed to the "chat" channel
|
71
|
-
And Bob is subscribed to the "chat" channel
|
72
|
-
When I trigger the "client-message" event on the "chat" channel
|
73
|
-
Then I should not receive a "client-message" event on the "chat" channel
|
74
|
-
And Bob should not receive a "client-message" event on the "chat" channel
|
75
|
-
|
76
|
-
Scenario: Server triggers an event on multiple private channels
|
77
|
-
Given I am subscribed to the "private-chat-1" channel
|
78
|
-
And Bob is subscribed to the "private-chat-2" channel
|
79
|
-
When a "message" event is triggered on the following channels:
|
80
|
-
| name |
|
81
|
-
| private-chat-1 |
|
82
|
-
| private-chat-2 |
|
83
|
-
Then I should receive a "message" event on the "private-chat-1" channel
|
84
|
-
And Bob should receive a "message" event on the "private-chat-2" channel
|
85
|
-
|
86
|
-
Scenario: Server triggers an event and excludes a client by socket ID
|
87
|
-
Given I am subscribed to the "chat" channel
|
88
|
-
And Bob is subscribed to the "chat" channel
|
89
|
-
When a "message" event is triggered on the "chat" channel, ignoring Bob
|
90
|
-
Then I should receive a "message" event on the "chat" channel
|
91
|
-
And Bob should not receive a "message" event on the "chat" channel
|
@@ -1,40 +0,0 @@
|
|
1
|
-
@javascript
|
2
|
-
Feature: Triggering channel webhooks
|
3
|
-
|
4
|
-
Background:
|
5
|
-
Given I am connected
|
6
|
-
And Bob is connected
|
7
|
-
|
8
|
-
Scenario: Occupying and vacating a channel
|
9
|
-
When I subscribe to the "game-1" channel
|
10
|
-
Then the server should have received the following event:
|
11
|
-
| name | channel_occupied |
|
12
|
-
| channel | game-1 |
|
13
|
-
When Bob is subscribed to the "game-1" channel
|
14
|
-
Then the server should have received no events
|
15
|
-
When Bob unsubscribes from the "game-1" channel
|
16
|
-
Then the server should have received no events
|
17
|
-
When I unsubscribe from the "game-1" channel
|
18
|
-
Then the server should have received the following event:
|
19
|
-
| name | channel_vacated |
|
20
|
-
| channel | game-1 |
|
21
|
-
|
22
|
-
Scenario: Subscribing and unsubscribing from a presence channel
|
23
|
-
When I subscribe to the "presence-chat-1" channel
|
24
|
-
Then the server should have received the following user event:
|
25
|
-
| name | member_added |
|
26
|
-
| channel | presence-chat-1 |
|
27
|
-
When Bob is subscribed to the "presence-chat-1" channel
|
28
|
-
Then the server should have received the following user event:
|
29
|
-
| user | Bob |
|
30
|
-
| name | member_added |
|
31
|
-
| channel | presence-chat-1 |
|
32
|
-
When Bob unsubscribes from the "presence-chat-1" channel
|
33
|
-
Then the server should have received the following user event:
|
34
|
-
| user | Bob |
|
35
|
-
| name | member_removed |
|
36
|
-
| channel | presence-chat-1 |
|
37
|
-
When I unsubscribe from the "presence-chat-1" channel
|
38
|
-
Then the server should have received the following user event:
|
39
|
-
| name | member_removed |
|
40
|
-
| channel | presence-chat-1 |
|
@@ -1,40 +0,0 @@
|
|
1
|
-
When %{I request "$path"} do |path|
|
2
|
-
wait do
|
3
|
-
@response = Pusher.get(path)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
When %{I request "$path" with the following options:} do |path, table|
|
8
|
-
wait do
|
9
|
-
begin
|
10
|
-
@response = Pusher.get(path, table.hashes.first)
|
11
|
-
rescue => error
|
12
|
-
@error = error
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Then %{I should receive the following JSON:} do |string|
|
18
|
-
expected = MultiJson.load(string)
|
19
|
-
expected = expected.inject({}) do |result, (key, value)|
|
20
|
-
result.merge(key.to_sym => value)
|
21
|
-
end
|
22
|
-
|
23
|
-
expect(@response).to eq(expected)
|
24
|
-
end
|
25
|
-
|
26
|
-
Then %{I should receive the following error:} do |string|
|
27
|
-
expect(@error.message).to include(string.strip)
|
28
|
-
end
|
29
|
-
|
30
|
-
Then /^I should receive JSON for (\d+) users?$/ do |count|
|
31
|
-
@response[:users].tap do |users|
|
32
|
-
expect(users.length).to eq(count.to_i)
|
33
|
-
|
34
|
-
users.map do |user|
|
35
|
-
ObjectSpace._id2ref(user["id"].to_i)
|
36
|
-
end.each do |object|
|
37
|
-
expect(object).to be_a(EventMachine::WebSocket::Connection)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
Given %{I am subscribed to the "$channel" channel} do |channel|
|
2
|
-
steps %{
|
3
|
-
When I subscribe to the "#{channel}" channel
|
4
|
-
Then I should be subscribed to the "#{channel}" channel
|
5
|
-
}
|
6
|
-
end
|
7
|
-
|
8
|
-
Given %{$name is subscribed to the "$channel" channel} do |name, channel|
|
9
|
-
using_session(name) do
|
10
|
-
step %{I am subscribed to the "#{channel}" channel}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
When %{I subscribe to the "$channel" channel} do |channel|
|
15
|
-
page.execute_script("Pusher.instance.subscribe(#{MultiJson.dump(channel)})")
|
16
|
-
end
|
17
|
-
|
18
|
-
When %{I subscribe to the "$channel" channel with presence events} do |channel|
|
19
|
-
page.execute_script(%{
|
20
|
-
var list = list || document.querySelector("section ul"),
|
21
|
-
count = count || document.querySelector("section header h1 span"),
|
22
|
-
addClient = addClient || function(client) {
|
23
|
-
var
|
24
|
-
element = list.appendChild(document.createElement("li"));
|
25
|
-
element.setAttribute("id", "client-" + client.id);
|
26
|
-
|
27
|
-
if (client.info) {
|
28
|
-
element.innerHTML = client.info.name;
|
29
|
-
}
|
30
|
-
},
|
31
|
-
changeCount = changeCount || function(delta) {
|
32
|
-
count.innerHTML = parseInt(count.innerHTML, 10) + delta;
|
33
|
-
};
|
34
|
-
|
35
|
-
Pusher.instance.subscribe(#{MultiJson.dump(channel)})
|
36
|
-
.bind("pusher:subscription_succeeded", function(clients) {
|
37
|
-
clients.each(addClient);
|
38
|
-
|
39
|
-
count.innerHTML = clients.count;
|
40
|
-
})
|
41
|
-
.bind("pusher:member_added", function(client) {
|
42
|
-
addClient(client);
|
43
|
-
changeCount(1);
|
44
|
-
})
|
45
|
-
.bind("pusher:member_removed", function(client) {
|
46
|
-
var item = list.querySelector("li#client-" + client.id);
|
47
|
-
|
48
|
-
list.removeChild(item);
|
49
|
-
|
50
|
-
changeCount(-1);
|
51
|
-
});
|
52
|
-
})
|
53
|
-
end
|
54
|
-
|
55
|
-
When %{I unsubscribe from the "$channel" channel} do |channel|
|
56
|
-
page.execute_script("Pusher.instance.unsubscribe(#{MultiJson.dump(channel)})")
|
57
|
-
end
|
58
|
-
|
59
|
-
When %{$name unsubscribes from the "$channel" channel} do |name, channel|
|
60
|
-
using_session(name) do
|
61
|
-
step %{I unsubscribe from the "#{channel}" channel}
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
Then %{I should be subscribed to the "$channel" channel} do |channel|
|
66
|
-
timeout_after(5) do
|
67
|
-
subscribed = page.evaluate_script(%{
|
68
|
-
var
|
69
|
-
channel = Pusher.instance.channel(#{MultiJson.dump(channel)});
|
70
|
-
channel && channel.subscribed;
|
71
|
-
})
|
72
|
-
subscribed == true
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
Then %{I should not be subscribed to the "$channel" channel} do |channel|
|
77
|
-
wait do
|
78
|
-
subscribed = page.evaluate_script(%{
|
79
|
-
var
|
80
|
-
channel = Pusher.instance.channel(#{MultiJson.dump(channel)});
|
81
|
-
channel && channel.subscribed;
|
82
|
-
})
|
83
|
-
|
84
|
-
expect(subscribed).to eq(false)
|
85
|
-
end
|
86
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
Given "I am connected" do
|
2
|
-
steps %{
|
3
|
-
Given I am on the homepage
|
4
|
-
Then I should be connected
|
5
|
-
}
|
6
|
-
end
|
7
|
-
|
8
|
-
Given %{$name is connected} do |name|
|
9
|
-
using_session(name) do
|
10
|
-
step %{I am connected}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Given "I change my socket ID" do
|
15
|
-
page.execute_script("Pusher.instance.connection.socket_id = -1;")
|
16
|
-
end
|
17
|
-
|
18
|
-
Then "I should be connected" do
|
19
|
-
timeout_after(5) do
|
20
|
-
state = page.evaluate_script("Pusher.instance.connection.state")
|
21
|
-
state == "connected"
|
22
|
-
end
|
23
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
When %{a "$event" event is triggered on the "$channel" channel} do |event, channel|
|
2
|
-
Pusher.trigger(channel, event, {})
|
3
|
-
end
|
4
|
-
|
5
|
-
When %{a "$event" event is triggered on the "$channel" channel, ignoring $name} do |event, channel, name|
|
6
|
-
name = nil if name == "me"
|
7
|
-
socket_id = nil
|
8
|
-
|
9
|
-
using_session(name) do
|
10
|
-
socket_id = page.evaluate_script("Pusher.instance.connection.socket_id")
|
11
|
-
end
|
12
|
-
|
13
|
-
Pusher.trigger(channel, event, {}, socket_id: socket_id)
|
14
|
-
end
|
15
|
-
|
16
|
-
When %{a "$event" event is triggered on the following channels:} do |event, table|
|
17
|
-
channels = table.hashes.collect { |hash| hash["name"] }
|
18
|
-
|
19
|
-
Pusher.trigger(channels, event, {})
|
20
|
-
end
|
21
|
-
|
22
|
-
When %{I trigger the "$event" event on the "$channel" channel} do |event, channel|
|
23
|
-
page.execute_script(%{
|
24
|
-
var
|
25
|
-
channel = Pusher.instance.channel(#{MultiJson.dump(channel)});
|
26
|
-
channel.trigger(#{MultiJson.dump(event)}, {});
|
27
|
-
})
|
28
|
-
end
|
29
|
-
|
30
|
-
When %{I manually trigger the "$event" event on the "$channel" channel} do |event, channel|
|
31
|
-
page.execute_script(%{Pusher.instance.send_event(#{MultiJson.dump(event)}, {}, #{MultiJson.dump(channel)})})
|
32
|
-
end
|
33
|
-
|
34
|
-
Then /^([^ ]+) should receive a "([^"]+)" event on the "([^"]+)" channel$/ do |name, event, channel|
|
35
|
-
name = nil if name == "I"
|
36
|
-
|
37
|
-
using_session(name) do
|
38
|
-
wait do
|
39
|
-
events = page.evaluate_script("Pusher.instance.events[#{MultiJson.dump([channel, event].join(":"))}]")
|
40
|
-
|
41
|
-
expect(events.length).to eq(1)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Then /^([^ ]+) should not receive a "([^"]+)" event on the "([^"]+)" channel$/ do |name, event, channel|
|
47
|
-
name = nil if name == "I"
|
48
|
-
|
49
|
-
using_session(name) do
|
50
|
-
wait do
|
51
|
-
events = page.evaluate_script("Pusher.instance.events[#{MultiJson.dump([channel, event].join(":"))}]")
|
52
|
-
|
53
|
-
expect(events).to be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
Then /^the server should have received the following (user )*event:$/ do |user_event, table|
|
2
|
-
event = table.transpose.hashes.first
|
3
|
-
|
4
|
-
using_session(event.delete("user")) do
|
5
|
-
page.evaluate_script("Pusher.instance.connection.socket_id").tap do |socket_id|
|
6
|
-
event.merge!("user_id" => socket_id.to_s)
|
7
|
-
end
|
8
|
-
end if user_event
|
9
|
-
|
10
|
-
timeout_after(5) do
|
11
|
-
$events.include?(event)
|
12
|
-
end
|
13
|
-
|
14
|
-
$events.replace([])
|
15
|
-
end
|
16
|
-
|
17
|
-
Then /^the server should have received no events$/ do
|
18
|
-
wait do
|
19
|
-
expect($events).to be_empty
|
20
|
-
end
|
21
|
-
end
|