slack-ruby-client 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop_todo.yml +15 -4
  4. data/CHANGELOG.md +7 -0
  5. data/README.md +8 -1
  6. data/Rakefile +1 -1
  7. data/bin/commands.rb +1 -0
  8. data/bin/commands/api.rb +2 -2
  9. data/bin/commands/apps.rb +2 -2
  10. data/bin/commands/apps_permissions.rb +4 -4
  11. data/bin/commands/apps_permissions_resources.rb +2 -2
  12. data/bin/commands/apps_permissions_scopes.rb +2 -2
  13. data/bin/commands/apps_permissions_users.rb +4 -4
  14. data/bin/commands/auth.rb +4 -4
  15. data/bin/commands/bots.rb +2 -2
  16. data/bin/commands/channels.rb +32 -31
  17. data/bin/commands/chat.rb +48 -17
  18. data/bin/commands/chat_scheduledMessages.rb +17 -0
  19. data/bin/commands/conversations.rb +35 -35
  20. data/bin/commands/dialog.rb +2 -2
  21. data/bin/commands/dnd.rb +9 -9
  22. data/bin/commands/emoji.rb +2 -2
  23. data/bin/commands/files.rb +14 -25
  24. data/bin/commands/files_comments.rb +2 -23
  25. data/bin/commands/groups.rb +33 -33
  26. data/bin/commands/im.rb +13 -13
  27. data/bin/commands/migration.rb +2 -2
  28. data/bin/commands/mpim.rb +11 -11
  29. data/bin/commands/oauth.rb +4 -4
  30. data/bin/commands/pins.rb +6 -6
  31. data/bin/commands/reactions.rb +8 -8
  32. data/bin/commands/reminders.rb +10 -10
  33. data/bin/commands/rtm.rb +4 -4
  34. data/bin/commands/search.rb +7 -7
  35. data/bin/commands/stars.rb +6 -6
  36. data/bin/commands/team.rb +8 -8
  37. data/bin/commands/team_profile.rb +2 -2
  38. data/bin/commands/usergroups.rb +11 -11
  39. data/bin/commands/usergroups_users.rb +4 -4
  40. data/bin/commands/users.rb +21 -22
  41. data/bin/commands/users_profile.rb +4 -4
  42. data/lib/slack/events/request.rb +9 -5
  43. data/lib/slack/real_time/client.rb +23 -6
  44. data/lib/slack/real_time/concurrency/async.rb +55 -23
  45. data/lib/slack/real_time/concurrency/celluloid.rb +0 -1
  46. data/lib/slack/real_time/concurrency/eventmachine.rb +0 -5
  47. data/lib/slack/real_time/socket.rb +16 -9
  48. data/lib/slack/version.rb +1 -1
  49. data/lib/slack/web/api/endpoints.rb +2 -0
  50. data/lib/slack/web/api/endpoints/api.rb +1 -1
  51. data/lib/slack/web/api/endpoints/apps.rb +1 -1
  52. data/lib/slack/web/api/endpoints/apps_permissions.rb +2 -2
  53. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +1 -1
  54. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +1 -1
  55. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +2 -2
  56. data/lib/slack/web/api/endpoints/auth.rb +2 -2
  57. data/lib/slack/web/api/endpoints/bots.rb +1 -1
  58. data/lib/slack/web/api/endpoints/channels.rb +18 -15
  59. data/lib/slack/web/api/endpoints/chat.rb +63 -9
  60. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +37 -0
  61. data/lib/slack/web/api/endpoints/conversations.rb +17 -17
  62. data/lib/slack/web/api/endpoints/dialog.rb +1 -1
  63. data/lib/slack/web/api/endpoints/dnd.rb +4 -4
  64. data/lib/slack/web/api/endpoints/emoji.rb +1 -1
  65. data/lib/slack/web/api/endpoints/files.rb +7 -18
  66. data/lib/slack/web/api/endpoints/files_comments.rb +1 -34
  67. data/lib/slack/web/api/endpoints/groups.rb +18 -16
  68. data/lib/slack/web/api/endpoints/im.rb +8 -6
  69. data/lib/slack/web/api/endpoints/migration.rb +1 -1
  70. data/lib/slack/web/api/endpoints/mpim.rb +7 -5
  71. data/lib/slack/web/api/endpoints/oauth.rb +2 -2
  72. data/lib/slack/web/api/endpoints/pins.rb +5 -3
  73. data/lib/slack/web/api/endpoints/reactions.rb +6 -4
  74. data/lib/slack/web/api/endpoints/reminders.rb +5 -5
  75. data/lib/slack/web/api/endpoints/rtm.rb +2 -2
  76. data/lib/slack/web/api/endpoints/search.rb +3 -3
  77. data/lib/slack/web/api/endpoints/stars.rb +5 -3
  78. data/lib/slack/web/api/endpoints/team.rb +5 -4
  79. data/lib/slack/web/api/endpoints/team_profile.rb +1 -1
  80. data/lib/slack/web/api/endpoints/usergroups.rb +5 -5
  81. data/lib/slack/web/api/endpoints/usergroups_users.rb +2 -2
  82. data/lib/slack/web/api/endpoints/users.rb +12 -12
  83. data/lib/slack/web/api/endpoints/users_profile.rb +2 -2
  84. data/spec/integration/integration_spec.rb +43 -36
  85. data/spec/slack/events/request_spec.rb +29 -1
  86. data/spec/slack/real_time/concurrency/celluloid_spec.rb +5 -0
  87. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +1 -0
  88. data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +7 -0
  89. data/spec/slack/web/api/endpoints/files_comments_spec.rb +0 -19
  90. data/spec/spec_helper.rb +5 -0
  91. metadata +6 -2
@@ -6,7 +6,8 @@ module Slack
6
6
  module Endpoints
7
7
  module Reactions
8
8
  #
9
- # Adds a reaction to an item.
9
+ # This method adds a reaction (emoji) to a message.
10
+ # Now that file threads work the way you'd expect, the file and file_comment arguments are deprecated. Specify channel and timestamp instead.
10
11
  #
11
12
  # @option options [Object] :name
12
13
  # Reaction (emoji) name.
@@ -27,7 +28,7 @@ module Slack
27
28
  end
28
29
 
29
30
  #
30
- # Gets reactions for an item.
31
+ # This method returns a list of all reactions for a single item (file, file comment, channel message, group message, or direct message).
31
32
  #
32
33
  # @option options [channel] :channel
33
34
  # Channel where the message to get reactions for was posted.
@@ -47,7 +48,7 @@ module Slack
47
48
  end
48
49
 
49
50
  #
50
- # Lists reactions made by a user.
51
+ # This method returns a list of all items (file, file comment, channel message, group message, or direct message) reacted to by a user.
51
52
  #
52
53
  # @option options [Object] :cursor
53
54
  # Parameter for pagination. Set cursor equal to the next_cursor attribute returned by the previous request's response_metadata. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection. See pagination for more details.
@@ -71,7 +72,8 @@ module Slack
71
72
  end
72
73
 
73
74
  #
74
- # Removes a reaction from an item.
75
+ # This method removes a reaction (emoji) from an item (file, file comment, channel message, group message, or direct message).
76
+ # One of file, file_comment, or the combination of channel and timestamp must be specified.
75
77
  #
76
78
  # @option options [Object] :name
77
79
  # Reaction (emoji) name.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Reminders
8
8
  #
9
- # Creates a reminder.
9
+ # This method creates a reminder.
10
10
  #
11
11
  # @option options [Object] :text
12
12
  # The content of the reminder.
@@ -24,7 +24,7 @@ module Slack
24
24
  end
25
25
 
26
26
  #
27
- # Marks a reminder as complete.
27
+ # This method completes a reminder.
28
28
  #
29
29
  # @option options [Object] :reminder
30
30
  # The ID of the reminder to be marked as complete.
@@ -36,7 +36,7 @@ module Slack
36
36
  end
37
37
 
38
38
  #
39
- # Deletes a reminder.
39
+ # This method deletes a reminder.
40
40
  #
41
41
  # @option options [Object] :reminder
42
42
  # The ID of the reminder.
@@ -48,7 +48,7 @@ module Slack
48
48
  end
49
49
 
50
50
  #
51
- # Gets information about a reminder.
51
+ # This method returns information about a reminder.
52
52
  #
53
53
  # @option options [Object] :reminder
54
54
  # The ID of the reminder.
@@ -60,7 +60,7 @@ module Slack
60
60
  end
61
61
 
62
62
  #
63
- # Lists all reminders created by or for a given user.
63
+ # This method lists all reminders created by or for a given user.
64
64
  #
65
65
  # @see https://api.slack.com/methods/reminders.list
66
66
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/reminders/reminders.list.json
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Rtm
8
8
  #
9
- # Starts a Real Time Messaging session.
9
+ # This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.
10
10
  #
11
11
  # @option options [Object] :batch_presence_aware
12
12
  # Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. See batch presence.
@@ -19,7 +19,7 @@ module Slack
19
19
  end
20
20
 
21
21
  #
22
- # Starts a Real Time Messaging session.
22
+ # This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.
23
23
  #
24
24
  # @option options [Object] :batch_presence_aware
25
25
  # Batch presence deliveries via subscription. Enabling changes the shape of presence_change events. See batch presence.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Search
8
8
  #
9
- # Searches for messages and files matching a query.
9
+ # This method allows users and applications to search both messages and files in a single call.
10
10
  #
11
11
  # @option options [Object] :query
12
12
  # Search query. May contains booleans, etc.
@@ -24,7 +24,7 @@ module Slack
24
24
  end
25
25
 
26
26
  #
27
- # Searches for files matching a query.
27
+ # This method returns files matching a search query.
28
28
  #
29
29
  # @option options [Object] :query
30
30
  # Search query.
@@ -42,7 +42,7 @@ module Slack
42
42
  end
43
43
 
44
44
  #
45
- # Searches for messages matching a query.
45
+ # This method returns messages matching a search query.
46
46
  #
47
47
  # @option options [Object] :query
48
48
  # Search query.
@@ -6,7 +6,8 @@ module Slack
6
6
  module Endpoints
7
7
  module Stars
8
8
  #
9
- # Adds a star to an item.
9
+ # This method adds a star to an item (message, file, file comment, channel, private group, or DM) on behalf of the authenticated user.
10
+ # One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
10
11
  #
11
12
  # @option options [channel] :channel
12
13
  # Channel to add star to, or channel where the message to add star to was posted (used with timestamp).
@@ -24,7 +25,7 @@ module Slack
24
25
  end
25
26
 
26
27
  #
27
- # Lists stars for a user.
28
+ # This method lists the items starred by the authed user.
28
29
  #
29
30
  # @option options [Object] :cursor
30
31
  # Parameter for pagination. Set cursor equal to the next_cursor attribute returned by the previous request's response_metadata. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection. See pagination for more details.
@@ -43,7 +44,8 @@ module Slack
43
44
  end
44
45
 
45
46
  #
46
- # Removes a star from an item.
47
+ # This method removes a star from an item (message, file, file comment, channel, private group, or DM) on behalf of the authenticated user.
48
+ # One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
47
49
  #
48
50
  # @option options [channel] :channel
49
51
  # Channel to remove star from, or channel where the message to remove star from was posted (used with timestamp).
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Team
8
8
  #
9
- # Gets the access logs for the current team.
9
+ # This method is used to retrieve the "access logs" for users on a workspace.
10
10
  #
11
11
  # @option options [Object] :before
12
12
  # End of time range of logs to include in results (inclusive).
@@ -17,7 +17,8 @@ module Slack
17
17
  end
18
18
 
19
19
  #
20
- # Gets billable users information for the current team.
20
+ # This method lists billable information for each user on the team. Currently this consists solely of whether the user is
21
+ # subject to billing per Slack's Fair Billing policy.
21
22
  #
22
23
  # @option options [user] :user
23
24
  # A user to retrieve the billable information for. Defaults to all users.
@@ -29,7 +30,7 @@ module Slack
29
30
  end
30
31
 
31
32
  #
32
- # Gets information about the current team.
33
+ # This method provides information about your team.
33
34
  #
34
35
  # @see https://api.slack.com/methods/team.info
35
36
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/team/team.info.json
@@ -38,7 +39,7 @@ module Slack
38
39
  end
39
40
 
40
41
  #
41
- # Gets the integration logs for the current team.
42
+ # This method lists the integration activity logs for a team, including when integrations are added, modified and removed. This method can only be called by Admins.
42
43
  #
43
44
  # @option options [Object] :app_id
44
45
  # Filter logs to this Slack app. Defaults to all logs.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module TeamProfile
8
8
  #
9
- # Retrieve a team's profile.
9
+ # This method is used to get the profile field definitions for this team.
10
10
  #
11
11
  # @option options [Object] :visibility
12
12
  # Filter by visibility.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Usergroups
8
8
  #
9
- # Create a User Group
9
+ # This method is used to create a User Group.
10
10
  #
11
11
  # @option options [Object] :name
12
12
  # A name for the User Group. Must be unique among User Groups.
@@ -26,7 +26,7 @@ module Slack
26
26
  end
27
27
 
28
28
  #
29
- # Disable an existing User Group
29
+ # This method disables an existing User Group.
30
30
  #
31
31
  # @option options [Object] :usergroup
32
32
  # The encoded ID of the User Group to disable.
@@ -40,7 +40,7 @@ module Slack
40
40
  end
41
41
 
42
42
  #
43
- # Enable a User Group
43
+ # This method enables a User Group which was previously disabled.
44
44
  #
45
45
  # @option options [Object] :usergroup
46
46
  # The encoded ID of the User Group to enable.
@@ -54,7 +54,7 @@ module Slack
54
54
  end
55
55
 
56
56
  #
57
- # List all User Groups for a team
57
+ # This method returns a list of all User Groups in the team. This can optionally include disabled User Groups.
58
58
  #
59
59
  # @option options [Object] :include_count
60
60
  # Include the number of users in each User Group.
@@ -69,7 +69,7 @@ module Slack
69
69
  end
70
70
 
71
71
  #
72
- # Update an existing User Group
72
+ # This method updates the properties of an existing User Group.
73
73
  #
74
74
  # @option options [Object] :usergroup
75
75
  # The encoded ID of the User Group to update.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module UsergroupsUsers
8
8
  #
9
- # List all users in a User Group
9
+ # This method returns a list of all users within a User Group.
10
10
  #
11
11
  # @option options [Object] :usergroup
12
12
  # The encoded ID of the User Group to update.
@@ -20,7 +20,7 @@ module Slack
20
20
  end
21
21
 
22
22
  #
23
- # Update the list of users for a User Group
23
+ # This method updates the list of users that belong to a User Group. This method replaces all users in a User Group with the list of users provided in the users parameter.
24
24
  #
25
25
  # @option options [Object] :usergroup
26
26
  # The encoded ID of the User Group to update.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module Users
8
8
  #
9
- # List conversations the calling user may access.
9
+ # As part of the Conversations API, this method's required scopes depend on the type of channel-like object you're working with. For classic Slack apps, a corresponding channels: scope is required when working with public channels, groups: for private channels, also the same rules are applied for im: and mpim:. For workspace apps, a conversations: scope is all that's needed.
10
10
  #
11
11
  # @option options [Object] :cursor
12
12
  # Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first "page" of the collection. See pagination for more detail.
@@ -32,7 +32,7 @@ module Slack
32
32
  end
33
33
 
34
34
  #
35
- # Delete the user profile photo
35
+ # This method allows the user to delete their profile image. It will clear whatever image is currently set.
36
36
  #
37
37
  # @see https://api.slack.com/methods/users.deletePhoto
38
38
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.deletePhoto.json
@@ -41,7 +41,8 @@ module Slack
41
41
  end
42
42
 
43
43
  #
44
- # Gets user presence information.
44
+ # This method lets you find out information about a user's presence.
45
+ # Consult the presence documentation for more details.
45
46
  #
46
47
  # @option options [user] :user
47
48
  # User to get presence info on. Defaults to the authed user.
@@ -54,7 +55,7 @@ module Slack
54
55
  end
55
56
 
56
57
  #
57
- # Get a user's identity.
58
+ # After your Slack app is awarded an identity token through Sign in with Slack, use this method to retrieve a user's identity.
58
59
  #
59
60
  # @see https://api.slack.com/methods/users.identity
60
61
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.identity.json
@@ -63,7 +64,7 @@ module Slack
63
64
  end
64
65
 
65
66
  #
66
- # Gets information about a user.
67
+ # This method returns information about a member of a workspace.
67
68
  #
68
69
  # @option options [user] :user
69
70
  # User to get info on.
@@ -78,7 +79,7 @@ module Slack
78
79
  end
79
80
 
80
81
  #
81
- # Lists all users in a Slack team.
82
+ # This method returns a list of all users in the workspace. This includes deleted/deactivated users.
82
83
  #
83
84
  # @option options [Object] :cursor
84
85
  # Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first "page" of the collection. See pagination for more detail.
@@ -86,8 +87,6 @@ module Slack
86
87
  # Set this to true to receive the locale for users. Defaults to false.
87
88
  # @option options [Object] :limit
88
89
  # The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
89
- # @option options [Object] :presence
90
- # Deprecated. Whether to include presence data in the output. Defaults to false. Setting this to true reduces performance, especially with large teams.
91
90
  # @see https://api.slack.com/methods/users.list
92
91
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.list.json
93
92
  def users_list(options = {})
@@ -101,7 +100,7 @@ module Slack
101
100
  end
102
101
 
103
102
  #
104
- # Find a user with an email address.
103
+ # Retrieve a single user by looking them up by their registered email address. Requires users:read.email.
105
104
  #
106
105
  # @option options [Object] :email
107
106
  # An email address belonging to a user in the workspace.
@@ -113,7 +112,7 @@ module Slack
113
112
  end
114
113
 
115
114
  #
116
- # Marked a user as active. Deprecated and non-functional.
115
+ # This method is no longer functional and the behavior it controlled is no longer offered. The method will no longer exist beginning May 8, 2018.
117
116
  #
118
117
  # @see https://api.slack.com/methods/users.setActive
119
118
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.setActive.json
@@ -122,7 +121,7 @@ module Slack
122
121
  end
123
122
 
124
123
  #
125
- # Set the user profile photo
124
+ # This method allows the user to set their profile image. The caller can pass image data via image.
126
125
  #
127
126
  # @option options [Object] :image
128
127
  # File contents via multipart/form-data.
@@ -140,7 +139,8 @@ module Slack
140
139
  end
141
140
 
142
141
  #
143
- # Manually sets user presence.
142
+ # This method lets you set the calling user's manual presence.
143
+ # Consult the presence documentation for more details.
144
144
  #
145
145
  # @option options [Object] :presence
146
146
  # Either auto or away.
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module UsersProfile
8
8
  #
9
- # Retrieves a user's profile information.
9
+ # Use this method to retrieve a user's profile information.
10
10
  #
11
11
  # @option options [Object] :include_labels
12
12
  # Include labels for each ID in custom profile fields.
@@ -20,7 +20,7 @@ module Slack
20
20
  end
21
21
 
22
22
  #
23
- # Set the profile information for a user.
23
+ # Use this method to set a user's profile information, including name, email, current status, and other attributes.
24
24
  #
25
25
  # @option options [Object] :name
26
26
  # Name of a single key to set. Usable only if profile is not passed.
@@ -19,8 +19,6 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
19
19
  Slack.configure do |slack|
20
20
  slack.logger = logger
21
21
  end
22
-
23
- @queue = QueueWithTimeout.new
24
22
  end
25
23
 
26
24
  after do
@@ -29,38 +27,41 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
29
27
 
30
28
  let(:client) { Slack::RealTime::Client.new(token: ENV['SLACK_API_TOKEN']) }
31
29
 
32
- let(:queue) { @queue }
33
-
34
- def start
35
- # starts the client and pushes an item on a queue when connected
36
- client.start_async do |driver|
37
- driver.on :open do |data|
38
- logger.debug "connection.on :open, data=#{data}"
39
- queue.push nil
40
- end
41
- end
42
- end
30
+ let!(:queue) { @queue = QueueWithTimeout.new }
43
31
 
44
32
  before do
45
33
  client.on :hello do
46
34
  logger.info "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
47
35
  end
48
36
 
37
+ client.on :message do |event|
38
+ logger.info " #{event.class}"
39
+ end
40
+
49
41
  client.on :close do
50
42
  logger.info 'Disconnecting ...'
51
43
  # pushes another item to the queue when disconnected
52
- queue.push nil if @queue
44
+ queue.push :closed
53
45
  end
54
46
  end
55
47
 
56
48
  def start_server
57
- dt = rand(2..6)
49
+ dt = rand(10..20)
58
50
  logger.debug "#start_server, waiting #{dt} second(s)"
59
51
  sleep dt # prevent Slack 429 rate limit errors
60
- # start server and wait for on :open
61
- @server = start
52
+ # starts the client and pushes an item on a queue when connected
53
+ @server = client.start_async do |driver|
54
+ driver.on :open do |data|
55
+ logger.debug "connection.on :open, data=#{data}"
56
+ queue.push :opened
57
+ end
58
+
59
+ driver.on :hello do |data|
60
+ logger.debug "connection.on :hello, data=#{data}"
61
+ end
62
+ end
62
63
  logger.debug "started #{@server}"
63
- queue.pop_with_timeout(5)
64
+ expect(queue.pop_with_timeout(5)).to eq :opened
64
65
  end
65
66
 
66
67
  def wait_for_server
@@ -72,27 +73,16 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
72
73
  @queue = nil
73
74
  end
74
75
 
75
- def stop_server
76
- logger.debug '#stop_server'
77
- client.stop!
78
- logger.debug '#stop_server, stopped'
79
- end
80
-
81
76
  after do
82
- wait_for_server
77
+ wait_for_server # wait for :closed to be pushed on queue
83
78
  @server.join if @server.is_a?(::Thread)
84
79
  end
85
80
 
86
81
  context 'client connected' do
87
- before do
88
- start_server
89
- end
90
-
91
82
  let(:channel) { "@#{client.self.id}" }
83
+ let(:message) { SecureRandom.hex }
92
84
 
93
85
  it 'responds to message' do
94
- message = SecureRandom.hex
95
-
96
86
  client.on :message do |data|
97
87
  logger.debug data
98
88
  # concurrent execution of tests causes messages to arrive in any order
@@ -105,13 +95,19 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
105
95
  client.stop!
106
96
  end
107
97
 
98
+ start_server
99
+
108
100
  logger.debug "chat_postMessage, channel=#{channel}, message=#{message}"
109
101
  client.web_client.chat_postMessage channel: channel, text: message
110
102
  end
111
103
 
112
104
  it 'sends message' do
113
- client.message(channel: channel, text: 'Hello world!')
114
- client.stop!
105
+ client.on :hello do
106
+ expect(client.message(channel: channel, text: message)).to be true
107
+ client.stop!
108
+ end
109
+
110
+ start_server
115
111
  end
116
112
  end
117
113
 
@@ -127,19 +123,23 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
127
123
 
128
124
  context 'with websocket_ping set' do
129
125
  before do
130
- client.websocket_ping = 2
126
+ client.websocket_ping = 1
131
127
  end
128
+
132
129
  it 'sends pings' do
133
130
  @reply_to = nil
134
131
  client.on :pong do |data|
135
132
  @reply_to = data.reply_to
136
- queue.push nil
133
+ queue.push :pong
137
134
  client.stop!
138
135
  end
136
+
139
137
  start_server
138
+
140
139
  queue.pop_with_timeout(5)
141
140
  expect(@reply_to).to be 1
142
141
  end
142
+
143
143
  it 'rebuilds the websocket connection when dropped' do
144
144
  @reply_to = nil
145
145
  client.on :pong do |data|
@@ -148,11 +148,13 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
148
148
  client.instance_variable_get(:@socket).close
149
149
  else
150
150
  expect(@reply_to).to be 2
151
- queue.push nil
151
+ queue.push :pong
152
152
  client.stop!
153
153
  end
154
154
  end
155
+
155
156
  start_server
157
+
156
158
  queue.pop_with_timeout(10)
157
159
  queue.pop_with_timeout(10)
158
160
  end
@@ -162,16 +164,21 @@ RSpec.describe 'integration test', skip: (!ENV['SLACK_API_TOKEN'] || !ENV['CONCU
162
164
  before do
163
165
  client.websocket_ping = 0
164
166
  end
167
+
165
168
  it 'does not send pings' do
166
169
  @reply_to = nil
170
+
167
171
  client.on :pong do |data|
168
172
  @reply_to = data.reply_to
169
173
  end
174
+
170
175
  client.on :hello do
171
176
  client.stop!
172
177
  end
178
+
173
179
  start_server
174
180
  wait_for_server
181
+
175
182
  expect(@reply_to).to be nil
176
183
  end
177
184
  end