slack-ruby-client 0.14.4 → 0.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -11
  3. data/.rubocop_todo.yml +66 -47
  4. data/CHANGELOG.md +8 -0
  5. data/Dangerfile +1 -0
  6. data/Gemfile +1 -0
  7. data/README.md +16 -9
  8. data/Rakefile +1 -0
  9. data/bin/commands.rb +6 -0
  10. data/bin/commands/admin_apps.rb +27 -0
  11. data/bin/commands/admin_apps_requests.rb +16 -0
  12. data/bin/commands/admin_users_session.rb +3 -2
  13. data/bin/commands/api.rb +3 -2
  14. data/bin/commands/apps.rb +3 -2
  15. data/bin/commands/apps_permissions.rb +5 -4
  16. data/bin/commands/apps_permissions_resources.rb +3 -2
  17. data/bin/commands/apps_permissions_scopes.rb +3 -2
  18. data/bin/commands/apps_permissions_users.rb +5 -4
  19. data/bin/commands/auth.rb +5 -4
  20. data/bin/commands/bots.rb +3 -2
  21. data/bin/commands/channels.rb +31 -30
  22. data/bin/commands/chat.rb +19 -18
  23. data/bin/commands/chat_scheduledMessages.rb +3 -2
  24. data/bin/commands/conversations.rb +35 -34
  25. data/bin/commands/dialog.rb +3 -2
  26. data/bin/commands/dnd.rb +9 -8
  27. data/bin/commands/emoji.rb +3 -2
  28. data/bin/commands/files.rb +13 -12
  29. data/bin/commands/files_comments.rb +3 -2
  30. data/bin/commands/files_remote.rb +78 -0
  31. data/bin/commands/groups.rb +33 -32
  32. data/bin/commands/im.rb +13 -12
  33. data/bin/commands/migration.rb +3 -2
  34. data/bin/commands/mpim.rb +11 -10
  35. data/bin/commands/oauth.rb +5 -4
  36. data/bin/commands/oauth_v2.rb +17 -0
  37. data/bin/commands/pins.rb +7 -8
  38. data/bin/commands/reactions.rb +10 -11
  39. data/bin/commands/reminders.rb +11 -10
  40. data/bin/commands/rtm.rb +5 -4
  41. data/bin/commands/search.rb +7 -6
  42. data/bin/commands/stars.rb +7 -6
  43. data/bin/commands/team.rb +9 -8
  44. data/bin/commands/team_profile.rb +3 -2
  45. data/bin/commands/usergroups.rb +11 -10
  46. data/bin/commands/usergroups_users.rb +5 -4
  47. data/bin/commands/users.rb +21 -20
  48. data/bin/commands/users_admin.rb +1 -0
  49. data/bin/commands/users_prefs.rb +1 -0
  50. data/bin/commands/users_profile.rb +5 -4
  51. data/bin/commands/views.rb +48 -0
  52. data/bin/slack +1 -2
  53. data/examples/hi_real_time/Gemfile +1 -0
  54. data/examples/hi_real_time/hi.rb +7 -3
  55. data/examples/hi_real_time_and_web/Gemfile +1 -0
  56. data/examples/hi_real_time_and_web/hi.rb +7 -3
  57. data/examples/hi_real_time_async_async/Gemfile +1 -0
  58. data/examples/hi_real_time_async_async/hi.rb +6 -2
  59. data/examples/hi_real_time_async_celluloid/Gemfile +1 -0
  60. data/examples/hi_real_time_async_celluloid/hi.rb +7 -3
  61. data/examples/hi_real_time_async_eventmachine/Gemfile +1 -0
  62. data/examples/hi_real_time_async_eventmachine/hi.rb +7 -3
  63. data/examples/hi_web/Gemfile +1 -0
  64. data/examples/hi_web/hi.rb +1 -0
  65. data/examples/new_ticket/Gemfile +1 -0
  66. data/examples/new_ticket/new_ticket.rb +1 -0
  67. data/lib/slack-ruby-client.rb +3 -2
  68. data/lib/slack.rb +1 -0
  69. data/lib/slack/config.rb +1 -0
  70. data/lib/slack/events/config.rb +1 -0
  71. data/lib/slack/events/request.rb +3 -1
  72. data/lib/slack/logger.rb +6 -5
  73. data/lib/slack/messages/formatting.rb +1 -0
  74. data/lib/slack/messages/message.rb +1 -0
  75. data/lib/slack/real_time/api/message.rb +3 -1
  76. data/lib/slack/real_time/api/message_id.rb +1 -0
  77. data/lib/slack/real_time/api/ping.rb +5 -2
  78. data/lib/slack/real_time/api/typing.rb +3 -1
  79. data/lib/slack/real_time/client.rb +19 -12
  80. data/lib/slack/real_time/concurrency.rb +1 -0
  81. data/lib/slack/real_time/concurrency/async.rb +15 -7
  82. data/lib/slack/real_time/concurrency/celluloid.rb +9 -3
  83. data/lib/slack/real_time/concurrency/eventmachine.rb +7 -4
  84. data/lib/slack/real_time/config.rb +6 -1
  85. data/lib/slack/real_time/models.rb +1 -0
  86. data/lib/slack/real_time/models/base.rb +1 -0
  87. data/lib/slack/real_time/models/bot.rb +1 -0
  88. data/lib/slack/real_time/models/channel.rb +1 -0
  89. data/lib/slack/real_time/models/group.rb +1 -0
  90. data/lib/slack/real_time/models/im.rb +1 -0
  91. data/lib/slack/real_time/models/team.rb +1 -0
  92. data/lib/slack/real_time/models/user.rb +1 -0
  93. data/lib/slack/real_time/socket.rb +14 -11
  94. data/lib/slack/real_time/stores.rb +1 -0
  95. data/lib/slack/real_time/stores/base.rb +1 -0
  96. data/lib/slack/real_time/stores/starter.rb +1 -0
  97. data/lib/slack/real_time/stores/store.rb +16 -25
  98. data/lib/slack/version.rb +2 -1
  99. data/lib/slack/web/api/endpoints.rb +11 -0
  100. data/lib/slack/web/api/endpoints/admin_apps.rb +42 -0
  101. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +33 -0
  102. data/lib/slack/web/api/endpoints/admin_users_session.rb +2 -1
  103. data/lib/slack/web/api/endpoints/api.rb +2 -1
  104. data/lib/slack/web/api/endpoints/apps.rb +2 -1
  105. data/lib/slack/web/api/endpoints/apps_permissions.rb +3 -2
  106. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +2 -1
  107. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +2 -1
  108. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +3 -2
  109. data/lib/slack/web/api/endpoints/auth.rb +3 -2
  110. data/lib/slack/web/api/endpoints/bots.rb +2 -1
  111. data/lib/slack/web/api/endpoints/channels.rb +16 -16
  112. data/lib/slack/web/api/endpoints/chat.rb +10 -9
  113. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +2 -1
  114. data/lib/slack/web/api/endpoints/conversations.rb +18 -17
  115. data/lib/slack/web/api/endpoints/dialog.rb +2 -1
  116. data/lib/slack/web/api/endpoints/dnd.rb +5 -4
  117. data/lib/slack/web/api/endpoints/emoji.rb +2 -1
  118. data/lib/slack/web/api/endpoints/files.rb +7 -6
  119. data/lib/slack/web/api/endpoints/files_comments.rb +2 -1
  120. data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
  121. data/lib/slack/web/api/endpoints/groups.rb +17 -22
  122. data/lib/slack/web/api/endpoints/im.rb +7 -8
  123. data/lib/slack/web/api/endpoints/migration.rb +2 -1
  124. data/lib/slack/web/api/endpoints/mpim.rb +6 -7
  125. data/lib/slack/web/api/endpoints/oauth.rb +3 -2
  126. data/lib/slack/web/api/endpoints/oauth_v2.rb +30 -0
  127. data/lib/slack/web/api/endpoints/pins.rb +5 -9
  128. data/lib/slack/web/api/endpoints/reactions.rb +9 -12
  129. data/lib/slack/web/api/endpoints/reminders.rb +6 -5
  130. data/lib/slack/web/api/endpoints/rtm.rb +3 -2
  131. data/lib/slack/web/api/endpoints/search.rb +4 -3
  132. data/lib/slack/web/api/endpoints/stars.rb +4 -5
  133. data/lib/slack/web/api/endpoints/team.rb +5 -5
  134. data/lib/slack/web/api/endpoints/team_profile.rb +2 -1
  135. data/lib/slack/web/api/endpoints/usergroups.rb +6 -5
  136. data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -2
  137. data/lib/slack/web/api/endpoints/users.rb +11 -16
  138. data/lib/slack/web/api/endpoints/users_admin.rb +1 -0
  139. data/lib/slack/web/api/endpoints/users_prefs.rb +1 -0
  140. data/lib/slack/web/api/endpoints/users_profile.rb +3 -2
  141. data/lib/slack/web/api/endpoints/views.rb +97 -0
  142. data/lib/slack/web/api/error.rb +1 -0
  143. data/lib/slack/web/api/errors/slack_error.rb +2 -1
  144. data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -0
  145. data/lib/slack/web/api/mixins.rb +1 -0
  146. data/lib/slack/web/api/mixins/channels.id.rb +1 -0
  147. data/lib/slack/web/api/mixins/groups.id.rb +1 -0
  148. data/lib/slack/web/api/mixins/ids.id.rb +4 -1
  149. data/lib/slack/web/api/mixins/users.id.rb +1 -0
  150. data/lib/slack/web/api/mixins/users.search.rb +1 -0
  151. data/lib/slack/web/api/patches/views.1.view-json.patch +40 -0
  152. data/lib/slack/web/api/patches/views.1.views-published.patch +16 -0
  153. data/lib/slack/web/api/templates/command.erb +1 -0
  154. data/lib/slack/web/api/templates/commands.erb +1 -0
  155. data/lib/slack/web/api/templates/endpoints.erb +1 -0
  156. data/lib/slack/web/api/templates/method.erb +1 -0
  157. data/lib/slack/web/api/templates/method_spec.erb +1 -0
  158. data/lib/slack/web/client.rb +1 -0
  159. data/lib/slack/web/config.rb +1 -0
  160. data/lib/slack/web/faraday/connection.rb +1 -0
  161. data/lib/slack/web/faraday/request.rb +1 -0
  162. data/lib/slack/web/faraday/response/raise_error.rb +7 -6
  163. data/lib/slack/web/pagination/cursor.rb +1 -0
  164. data/lib/slack_ruby_client.rb +1 -0
  165. data/lib/tasks/git.rake +1 -0
  166. data/lib/tasks/real_time.rake +12 -4
  167. data/lib/tasks/update.rake +1 -0
  168. data/lib/tasks/web.rake +17 -6
  169. data/screenshots/create-app.png +0 -0
  170. data/slack-ruby-client.gemspec +4 -1
  171. data/spec/integration/integration_spec.rb +16 -17
  172. data/spec/slack/config_spec.rb +2 -0
  173. data/spec/slack/events/config_spec.rb +8 -4
  174. data/spec/slack/events/request_spec.rb +67 -37
  175. data/spec/slack/messages/formatting_spec.rb +25 -13
  176. data/spec/slack/real_time/api/message_spec.rb +6 -1
  177. data/spec/slack/real_time/api/ping_spec.rb +2 -0
  178. data/spec/slack/real_time/api/typing_spec.rb +5 -1
  179. data/spec/slack/real_time/client_spec.rb +137 -39
  180. data/spec/slack/real_time/concurrency/celluloid_spec.rb +11 -6
  181. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +9 -1
  182. data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +2 -0
  183. data/spec/slack/real_time/event_handlers/bot_spec.rb +2 -1
  184. data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -6
  185. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +2 -1
  186. data/spec/slack/real_time/event_handlers/group_spec.rb +5 -4
  187. data/spec/slack/real_time/event_handlers/im_spec.rb +4 -3
  188. data/spec/slack/real_time/event_handlers/team_spec.rb +3 -1
  189. data/spec/slack/real_time/event_handlers/user_spec.rb +1 -0
  190. data/spec/slack/real_time/rtm_connect_spec.rb +1 -0
  191. data/spec/slack/real_time/rtm_start_spec.rb +1 -0
  192. data/spec/slack/real_time/store_spec.rb +2 -1
  193. data/spec/slack/slack_spec.rb +37 -5
  194. data/spec/slack/version_spec.rb +2 -1
  195. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
  196. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +8 -0
  197. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +1 -0
  198. data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
  199. data/spec/slack/web/api/endpoints/apps_permissions_resources_spec.rb +1 -0
  200. data/spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb +1 -0
  201. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +1 -0
  202. data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +1 -0
  203. data/spec/slack/web/api/endpoints/apps_spec.rb +1 -0
  204. data/spec/slack/web/api/endpoints/bots_spec.rb +1 -0
  205. data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +1 -0
  206. data/spec/slack/web/api/endpoints/conversations_spec.rb +1 -0
  207. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +5 -1
  208. data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +2 -0
  209. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +80 -25
  210. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +12 -4
  211. data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +2 -0
  212. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +6 -1
  213. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +95 -0
  214. data/spec/slack/web/api/endpoints/dnd_spec.rb +1 -0
  215. data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
  216. data/spec/slack/web/api/endpoints/files_comments_spec.rb +1 -0
  217. data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
  218. data/spec/slack/web/api/endpoints/files_spec.rb +1 -0
  219. data/spec/slack/web/api/endpoints/im_spec.rb +1 -0
  220. data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
  221. data/spec/slack/web/api/endpoints/mpim_spec.rb +1 -0
  222. data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -0
  223. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +13 -0
  224. data/spec/slack/web/api/endpoints/pins_spec.rb +5 -1
  225. data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
  226. data/spec/slack/web/api/endpoints/reminders_spec.rb +1 -0
  227. data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
  228. data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
  229. data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
  230. data/spec/slack/web/api/endpoints/team_profile_spec.rb +1 -0
  231. data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
  232. data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
  233. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +1 -0
  234. data/spec/slack/web/api/endpoints/users_admin_spec.rb +1 -0
  235. data/spec/slack/web/api/endpoints/users_prefs_spec.rb +1 -0
  236. data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
  237. data/spec/slack/web/api/endpoints/views_spec.rb +29 -0
  238. data/spec/slack/web/api/error_spec.rb +4 -2
  239. data/spec/slack/web/api/errors/service_unavailable_spec.rb +6 -3
  240. data/spec/slack/web/api/errors/slack_error_spec.rb +4 -2
  241. data/spec/slack/web/api/mixins/channels_spec.rb +17 -7
  242. data/spec/slack/web/api/mixins/groups_spec.rb +17 -7
  243. data/spec/slack/web/api/mixins/users_spec.rb +17 -8
  244. data/spec/slack/web/api/pagination/cursor_spec.rb +40 -10
  245. data/spec/slack/web/client_spec.rb +45 -18
  246. data/spec/slack/web/faraday/response/raise_error_spec.rb +16 -5
  247. data/spec/spec_helper.rb +2 -1
  248. data/spec/support/queue_with_timeout.rb +1 -0
  249. data/spec/support/real_time/concurrency/mock.rb +1 -0
  250. data/spec/support/real_time/connected_client.rb +9 -3
  251. data/spec/support/real_time/event.rb +1 -0
  252. data/spec/support/token.rb +1 -0
  253. data/spec/support/vcr.rb +1 -0
  254. metadata +59 -7
  255. data/screenshots/register-bot.png +0 -0
@@ -1,16 +1,25 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Slack::Events::Request do
5
+ subject(:request) do
6
+ described_class.new(http_request)
7
+ end
8
+
4
9
  before do
5
10
  Slack::Events.configure do |config|
6
11
  config.signing_secret = signing_secret
7
12
  config.signature_expires_in = 30
8
13
  end
9
14
  end
15
+
10
16
  let(:signing_secret) { 'ade6ca762ade4db0e7d31484cd616b9c' }
11
17
  let(:signature) { 'v0=91177eea054d65de0fc0f9b4ec57714307bc0ce2c5f3bf0d28b1b720c8f92ba2' }
12
18
  let(:timestamp) { '1547933148' }
13
- let(:body) { '{"token":"X34FAqCu8tmGEkEEpoDncnja","challenge":"P7sFXA4o3HV2hTx4zb4zcQ9yrvuQs8pDh6EacOxmMRj0tJaXfQFF","type":"url_verification"}' }
19
+ let(:body) do
20
+ '{"token":"X34FAqCu8tmGEkEEpoDncnja","challenge":' \
21
+ '"P7sFXA4o3HV2hTx4zb4zcQ9yrvuQs8pDh6EacOxmMRj0tJaXfQFF","type":"url_verification"}'
22
+ end
14
23
  let(:http_request) do
15
24
  double(
16
25
  headers: {
@@ -22,39 +31,48 @@ RSpec.describe Slack::Events::Request do
22
31
  )
23
32
  )
24
33
  end
25
- subject do
26
- Slack::Events::Request.new(http_request)
34
+
35
+ after do
36
+ Slack::Events.config.reset
27
37
  end
38
+
28
39
  it 'reads http request' do
29
- expect(subject.signature).to eq signature
30
- expect(subject.body).to eq body
31
- expect(subject.timestamp).to eq timestamp
32
- expect(subject.version).to eq 'v0'
40
+ expect(request.signature).to eq signature
41
+ expect(request.body).to eq body
42
+ expect(request.timestamp).to eq timestamp
43
+ expect(request.version).to eq 'v0'
33
44
  end
34
45
  context 'time' do
35
46
  after do
36
47
  Timecop.return
37
48
  end
49
+
38
50
  context 'with an invalid signature' do
39
51
  let(:signature) { 'v0=invalid' }
52
+
40
53
  before do
41
54
  Timecop.freeze(Time.at(timestamp.to_i))
42
55
  end
56
+
43
57
  it 'is invalid but not expired' do
44
- expect(subject).to_not be_valid
45
- expect(subject).to_not be_expired
58
+ expect(request).not_to be_valid
59
+ expect(request).not_to be_expired
46
60
  end
47
61
  end
62
+
48
63
  context 'with an invalid body' do
49
64
  let(:body) { 'invalid' }
65
+
50
66
  before do
51
67
  Timecop.freeze(Time.at(timestamp.to_i))
52
68
  end
69
+
53
70
  it 'is invalid but not expired' do
54
- expect(subject).to_not be_valid
55
- expect(subject).to_not be_expired
71
+ expect(request).not_to be_valid
72
+ expect(request).not_to be_expired
56
73
  end
57
74
  end
75
+
58
76
  context 'with an invalid signing secret' do
59
77
  before do
60
78
  Slack::Events.configure do |config|
@@ -62,88 +80,100 @@ RSpec.describe Slack::Events::Request do
62
80
  end
63
81
  Timecop.freeze(Time.at(timestamp.to_i))
64
82
  end
83
+
65
84
  it 'is invalid but not expired' do
66
- expect(subject).to_not be_valid
67
- expect(subject).to_not be_expired
85
+ expect(request).not_to be_valid
86
+ expect(request).not_to be_expired
68
87
  end
69
88
  end
89
+
70
90
  context 'within time window' do
71
91
  before do
72
92
  Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in - 1)
73
93
  end
94
+
74
95
  it 'is valid' do
75
- expect(subject).to be_valid
76
- expect(subject).to_not be_expired
96
+ expect(request).to be_valid
97
+ expect(request).not_to be_expired
77
98
  end
78
99
  it 'does not raise an error and returns true' do
79
- expect(subject.verify!).to be true
100
+ expect(request.verify!).to be true
80
101
  end
81
102
  end
103
+
82
104
  context 'after time window' do
83
105
  before do
84
106
  Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in + 1)
85
107
  end
108
+
86
109
  it 'is valid but expired' do
87
- expect(subject).to be_valid
88
- expect(subject).to be_expired
110
+ expect(request).to be_valid
111
+ expect(request).to be_expired
89
112
  end
90
113
  it 'raises an error on verify!' do
91
- expect { subject.verify! }.to raise_error Slack::Events::Request::TimestampExpired
114
+ expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
92
115
  end
93
116
  end
117
+
94
118
  context 'before time but within window' do
95
119
  before do
96
120
  Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in + 1)
97
121
  end
122
+
98
123
  it 'is valid and not expired' do
99
- expect(subject).to be_valid
100
- expect(subject).to_not be_expired
124
+ expect(request).to be_valid
125
+ expect(request).not_to be_expired
101
126
  end
102
127
  it 'does not raise an error on verify!' do
103
- expect(subject.verify!).to be true
128
+ expect(request.verify!).to be true
104
129
  end
105
130
  end
131
+
106
132
  context 'before time window' do
107
133
  before do
108
134
  Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in - 1)
109
135
  end
136
+
110
137
  it 'is valid but expired' do
111
- expect(subject).to be_valid
112
- expect(subject).to be_expired
138
+ expect(request).to be_valid
139
+ expect(request).to be_expired
113
140
  end
114
141
  it 'raises an error on verify!' do
115
- expect { subject.verify! }.to raise_error Slack::Events::Request::TimestampExpired
142
+ expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
116
143
  end
117
144
  end
118
145
  end
146
+
119
147
  context 'without global config' do
120
148
  before do
121
149
  Slack::Events.config.reset
122
150
  end
151
+
123
152
  context 'without a signing secret parameter' do
124
- subject do
125
- Slack::Events::Request.new(http_request)
153
+ subject(:request) do
154
+ described_class.new(http_request)
126
155
  end
156
+
127
157
  it 'raises MissingSigningSecret' do
128
- expect { subject.valid? }.to raise_error Slack::Events::Request::MissingSigningSecret
158
+ expect { request.valid? }.to raise_error Slack::Events::Request::MissingSigningSecret
129
159
  end
130
160
  end
161
+
131
162
  context 'with a signing secret parameter' do
132
- subject do
133
- Slack::Events::Request.new(http_request,
134
- signing_secret: signing_secret,
135
- signature_expires_in: 30)
163
+ subject(:request) do
164
+ described_class.new(http_request,
165
+ signing_secret: signing_secret,
166
+ signature_expires_in: 30)
136
167
  end
168
+
137
169
  before do
138
170
  Timecop.freeze(Time.at(timestamp.to_i))
139
171
  end
172
+
140
173
  it 'is valid and not expired' do
141
- expect(subject).to be_valid
142
- expect(subject).to_not be_expired
174
+ expect(request).to be_valid
175
+ expect(request).not_to be_expired
143
176
  end
144
177
  end
145
178
  end
146
- after do
147
- Slack::Events.config.reset
148
- end
149
179
  end
@@ -1,42 +1,54 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Slack::Messages::Formatting do
4
- subject do
5
- Slack::Messages::Formatting
5
+ subject(:formatting) do
6
+ described_class
6
7
  end
8
+
7
9
  context '#unescape' do
8
10
  it 'plain text' do
9
- expect(subject.unescape('plain text')).to eq 'plain text'
11
+ expect(formatting.unescape('plain text')).to eq 'plain text'
10
12
  end
11
13
  it 'decodes an HTML-encoded message' do
12
- expect(subject.unescape('Hello &amp; &lt;world&gt;')).to eq 'Hello & <world>'
14
+ expect(formatting.unescape('Hello &amp; &lt;world&gt;')).to eq 'Hello & <world>'
13
15
  end
14
16
  it 'unescapes a user reference' do
15
- expect(subject.unescape('Hey <@U024BE7LH|bob>, did you see my file?')).to eq 'Hey @bob, did you see my file?'
17
+ expect(formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?')).to(
18
+ eq('Hey @bob, did you see my file?')
19
+ )
16
20
  end
17
21
  it 'unescapes a user reference without a name' do
18
- expect(subject.unescape('<@U02BEFY4U> ^^^')).to eq '@U02BEFY4U ^^^'
22
+ expect(formatting.unescape('<@U02BEFY4U> ^^^')).to eq '@U02BEFY4U ^^^'
19
23
  end
20
24
  it 'unescapes a URL without text' do
21
- expect(subject.unescape('This message contains a URL <http://foo.com/>')).to eq 'This message contains a URL http://foo.com/'
25
+ expect(formatting.unescape('This message contains a URL <http://foo.com/>')).to(
26
+ eq('This message contains a URL http://foo.com/')
27
+ )
22
28
  end
23
29
  it 'unescapes a URL with text' do
24
- expect(subject.unescape('So does this one: <http://www.foo.com|www.foo.com>')).to eq 'So does this one: www.foo.com'
30
+ expect(formatting.unescape('So does this one: <http://www.foo.com|www.foo.com>')).to(
31
+ eq('So does this one: www.foo.com')
32
+ )
25
33
  end
26
34
  it 'removes mailto' do
27
- expect(subject.unescape('<mailto:bob@example.com|Bob>')).to eq 'Bob'
35
+ expect(formatting.unescape('<mailto:bob@example.com|Bob>')).to eq 'Bob'
28
36
  end
29
37
  it 'unlinkifies references' do
30
- expect(subject.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>')).to eq 'Hello @bob, say hi to @everyone in #general'
38
+ expect(
39
+ formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>')
40
+ ).to(
41
+ eq('Hello @bob, say hi to @everyone in #general')
42
+ )
31
43
  end
32
44
  it 'can handle a lone &gt;' do
33
- expect(subject.unescape('Hello <@U123|bob> &gt; file.txt')).to eq 'Hello @bob > file.txt'
45
+ expect(formatting.unescape('Hello <@U123|bob> &gt; file.txt')).to eq 'Hello @bob > file.txt'
34
46
  end
35
47
  it 'unescapes a double smart quote' do
36
- expect(subject.unescape('“hello”')).to eq '"hello"'
48
+ expect(formatting.unescape('“hello”')).to eq '"hello"'
37
49
  end
38
50
  it 'unescapes a single smart quote' do
39
- expect(subject.unescape('‘hello’')).to eq "'hello'"
51
+ expect(formatting.unescape('‘hello’')).to eq "'hello'"
40
52
  end
41
53
  end
42
54
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
@@ -7,8 +8,12 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
7
8
  before do
8
9
  allow(client).to receive(:next_id).and_return(42)
9
10
  end
11
+
10
12
  it 'sends message' do
11
- expect(socket).to receive(:send_data).with({ type: 'message', id: 42, text: 'hello world', channel: 'channel' }.to_json)
13
+ expect(socket).to(
14
+ receive(:send_data)
15
+ .with({ type: 'message', id: 42, text: 'hello world', channel: 'channel' }.to_json)
16
+ )
12
17
  client.message(text: 'hello world', channel: 'channel')
13
18
  end
14
19
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
@@ -7,6 +8,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
7
8
  before do
8
9
  allow(client).to receive(:next_id).and_return(42)
9
10
  end
11
+
10
12
  it 'sends message' do
11
13
  expect(socket).to receive(:send_data).with({ type: 'ping', id: 42 }.to_json)
12
14
  client.ping
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
@@ -7,8 +8,11 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
7
8
  before do
8
9
  allow(client).to receive(:next_id).and_return(42)
9
10
  end
11
+
10
12
  it 'sends a typing indicator' do
11
- expect(socket).to receive(:send_data).with({ type: 'typing', id: 42, channel: 'channel' }.to_json)
13
+ expect(socket).to(
14
+ receive(:send_data).with({ type: 'typing', id: 42, channel: 'channel' }.to_json)
15
+ )
12
16
  client.typing(channel: 'channel')
13
17
  end
14
18
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
- RSpec.describe Slack::RealTime::Client do
4
+ RSpec.describe Slack::RealTime::Client do # rubocop:disable Metrics/BlockLength
4
5
  let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket, on: true) }
6
+
5
7
  before do
6
8
  @token = ENV.delete('SLACK_API_TOKEN')
7
9
  Slack::Config.reset
@@ -10,63 +12,78 @@ RSpec.describe Slack::RealTime::Client do
10
12
  config.concurrency = Slack::RealTime::Concurrency::Mock
11
13
  end
12
14
  end
15
+
13
16
  after do
14
17
  ENV['SLACK_API_TOKEN'] = @token if @token
15
18
  end
19
+
16
20
  context 'token' do
17
21
  before do
18
22
  Slack.configure do |config|
19
23
  config.token = 'global default'
20
24
  end
21
25
  end
26
+
22
27
  it 'defaults token to global default' do
23
- client = Slack::RealTime::Client.new
28
+ client = described_class.new
24
29
  expect(client.token).to eq 'global default'
25
30
  expect(client.web_client.token).to eq 'global default'
26
31
  end
27
32
  context 'with real time config' do
28
33
  before do
29
- Slack::RealTime::Client.configure do |config|
34
+ described_class.configure do |config|
30
35
  config.token = 'custom real time token'
31
36
  end
32
37
  end
38
+
33
39
  it 'overrides token to real time config' do
34
- client = Slack::RealTime::Client.new
40
+ client = described_class.new
35
41
  expect(client.token).to eq 'custom real time token'
36
42
  expect(client.web_client.token).to eq 'custom real time token'
37
43
  end
38
44
  it 'overrides token to specific token' do
39
- client = Slack::RealTime::Client.new(token: 'local token')
45
+ client = described_class.new(token: 'local token')
40
46
  expect(client.token).to eq 'local token'
41
47
  expect(client.web_client.token).to eq 'local token'
42
48
  end
43
49
  end
44
50
  end
51
+
45
52
  context 'websocket_ping_timer' do
46
53
  context 'with defaults' do
47
- let(:client) { Slack::RealTime::Client.new }
54
+ let(:client) { described_class.new }
55
+
48
56
  it 'defaults to websocket_ping / 2' do
49
57
  expect(client.websocket_ping_timer).to eq 15
50
58
  end
51
59
  end
60
+
52
61
  context 'with websocket_ping value changed' do
53
- let(:client) { Slack::RealTime::Client.new(websocket_ping: 22) }
62
+ let(:client) { described_class.new(websocket_ping: 22) }
63
+
54
64
  it 'defaults to websocket_ping / 2' do
55
65
  expect(client.websocket_ping_timer).to eq 11
56
66
  end
57
67
  end
58
68
  end
59
- context 'client with a full store', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
60
- let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Store) }
69
+
70
+ context 'client with a full store',
71
+ vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
72
+ let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Store) }
61
73
  let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
74
+
62
75
  describe '#start!' do
63
76
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
77
+
64
78
  before do
65
- allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
79
+ allow(Slack::RealTime::Socket).to(
80
+ receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
81
+ )
66
82
  allow(socket).to receive(:connect!)
67
83
  allow(socket).to receive(:start_sync)
68
84
  client.start!
69
85
  end
86
+
70
87
  describe 'properties provided upon connection' do
71
88
  it 'sets url' do
72
89
  expect(client.url).to eq url
@@ -101,9 +118,12 @@ RSpec.describe Slack::RealTime::Client do
101
118
  expect(client.groups.count).to eq 1
102
119
  end
103
120
  it 'includes team name in to_s' do
104
- expect(client.to_s).to eq "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
121
+ expect(client.to_s).to eq(
122
+ "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
123
+ )
105
124
  end
106
125
  end
126
+
107
127
  it 'uses web client to fetch url' do
108
128
  expect(client.web_client).to be_a Slack::Web::Client
109
129
  end
@@ -117,9 +137,10 @@ RSpec.describe Slack::RealTime::Client do
117
137
  end
118
138
  describe '#stop!' do
119
139
  before do
120
- expect(socket).to receive(:disconnect!)
140
+ allow(socket).to receive(:disconnect!)
121
141
  client.stop!
122
142
  end
143
+
123
144
  it 'cannot be invoked twice' do
124
145
  client.instance_variable_set('@socket', nil) # caused by a :close callback
125
146
  expect do
@@ -127,12 +148,14 @@ RSpec.describe Slack::RealTime::Client do
127
148
  end.to raise_error Slack::RealTime::Client::ClientNotStartedError
128
149
  end
129
150
  end
151
+
130
152
  describe '#next_id' do
131
153
  it 'increments' do
132
154
  previous_id = client.send(:next_id)
133
155
  expect(client.send(:next_id)).to eq previous_id + 1
134
156
  end
135
157
  end
158
+
136
159
  context 'subclassed' do
137
160
  it 'runs event handlers' do
138
161
  event = Slack::RealTime::Event.new(
@@ -144,14 +167,19 @@ RSpec.describe Slack::RealTime::Client do
144
167
  end
145
168
  end
146
169
  end
170
+
147
171
  describe '#start_async' do
148
172
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
173
+
149
174
  before do
150
- allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
175
+ allow(Slack::RealTime::Socket).to(
176
+ receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
177
+ )
151
178
  allow(socket).to receive(:connect!)
152
179
  allow(socket).to receive(:start_async)
153
180
  client.start_async
154
181
  end
182
+
155
183
  describe '#run_ping!' do
156
184
  it 'sends ping messages when the websocket connection is idle' do
157
185
  allow(socket).to receive(:time_since_last_message).and_return(30)
@@ -165,34 +193,62 @@ RSpec.describe Slack::RealTime::Client do
165
193
  expect(socket).to receive(:restart_async)
166
194
  client.run_ping!
167
195
  end
168
- [EOFError, Errno::ECONNRESET, Errno::EPIPE, Faraday::ClientError].each do |err|
196
+ [
197
+ EOFError,
198
+ Errno::ECONNRESET,
199
+ Errno::EPIPE,
200
+ Faraday::ClientError,
201
+ Slack::Web::Api::Errors::SlackError
202
+ ].each do |err|
169
203
  context "raising #{err}" do
170
204
  it 'does not terminate the ping worker' do
171
205
  allow(socket).to receive(:time_since_last_message) { raise err }
172
- expect(socket).to_not receive(:send_data)
206
+ expect(socket).not_to receive(:send_data)
173
207
  client.run_ping!
174
208
  end
175
209
  end
176
210
  end
211
+ context 'raising Slack::Web::Api::Errors::SlackError' do
212
+ %w[invalid_auth account_inactive].each do |code|
213
+ context code do
214
+ it 'does not terminate the ping worker' do
215
+ allow(socket).to receive(:time_since_last_message) {
216
+ raise Slack::Web::Api::Errors::SlackError, code
217
+ }
218
+ expect(socket).not_to receive(:send_data)
219
+ expect do
220
+ client.run_ping!
221
+ end.to raise_error Slack::Web::Api::Errors::SlackError, code
222
+ end
223
+ end
224
+ end
225
+ end
177
226
  end
178
227
  end
228
+
179
229
  describe 'to_s' do
180
230
  it 'defaults to class instance' do
181
231
  expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
182
232
  end
183
233
  end
184
234
  end
235
+
185
236
  context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
186
- let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Starter) }
237
+ let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Starter) }
187
238
  let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
239
+
188
240
  describe '#start!' do
189
241
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
242
+
190
243
  before do
191
- allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
244
+ allow(Slack::RealTime::Socket).to(
245
+ receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
246
+ )
192
247
  allow(socket).to receive(:connect!)
193
248
  allow(socket).to receive(:start_sync)
194
249
  client.start!
195
250
  end
251
+
196
252
  describe 'properties provided upon connection' do
197
253
  it 'sets url' do
198
254
  expect(client.url).to eq url
@@ -222,9 +278,12 @@ RSpec.describe Slack::RealTime::Client do
222
278
  expect(client.groups).to be_nil
223
279
  end
224
280
  it 'includes team name in to_s' do
225
- expect(client.to_s).to eq "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
281
+ expect(client.to_s).to eq(
282
+ "id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
283
+ )
226
284
  end
227
285
  end
286
+
228
287
  it 'uses web client to fetch url' do
229
288
  expect(client.web_client).to be_a Slack::Web::Client
230
289
  end
@@ -238,9 +297,10 @@ RSpec.describe Slack::RealTime::Client do
238
297
  end
239
298
  describe '#stop!' do
240
299
  before do
241
- expect(socket).to receive(:disconnect!)
300
+ allow(socket).to receive(:disconnect!)
242
301
  client.stop!
243
302
  end
303
+
244
304
  it 'cannot be invoked twice' do
245
305
  client.instance_variable_set('@socket', nil) # caused by a :close callback
246
306
  expect do
@@ -248,6 +308,7 @@ RSpec.describe Slack::RealTime::Client do
248
308
  end.to raise_error Slack::RealTime::Client::ClientNotStartedError
249
309
  end
250
310
  end
311
+
251
312
  describe '#next_id' do
252
313
  it 'increments' do
253
314
  previous_id = client.send(:next_id)
@@ -256,9 +317,11 @@ RSpec.describe Slack::RealTime::Client do
256
317
  end
257
318
  end
258
319
  end
320
+
259
321
  context 'client with nil store', vcr: { cassette_name: 'web/rtm_connect' } do
260
- let(:client) { Slack::RealTime::Client.new(store_class: nil) }
322
+ let(:client) { described_class.new(store_class: nil) }
261
323
  let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
324
+
262
325
  it 'sets store to nil' do
263
326
  expect(client.store).to be nil
264
327
  end
@@ -267,7 +330,7 @@ RSpec.describe Slack::RealTime::Client do
267
330
  'type' => 'team_rename',
268
331
  'name' => 'New Team Name Inc.'
269
332
  )
270
- expect(client).to_not receive(:run_handlers)
333
+ expect(client).not_to receive(:run_handlers)
271
334
  client.send(:dispatch, event)
272
335
  end
273
336
  it 'self' do
@@ -282,8 +345,10 @@ RSpec.describe Slack::RealTime::Client do
282
345
  end
283
346
  end
284
347
  end
348
+
285
349
  context 'client with defaults' do
286
- let(:client) { Slack::RealTime::Client.new }
350
+ let(:client) { described_class.new }
351
+
287
352
  describe '#initialize' do
288
353
  it 'sets ping' do
289
354
  expect(client.websocket_ping).to eq 30
@@ -303,6 +368,7 @@ RSpec.describe Slack::RealTime::Client do
303
368
  end
304
369
  end
305
370
  end
371
+
306
372
  describe '#run_ping?' do
307
373
  it 'returns true when websocket_ping is greater than 0' do
308
374
  client.websocket_ping = 30
@@ -316,20 +382,24 @@ RSpec.describe Slack::RealTime::Client do
316
382
  end
317
383
  end
318
384
  end
385
+
319
386
  context 'with custom settings' do
320
387
  describe '#initialize' do
321
388
  Slack::RealTime::Config::ATTRIBUTES.each do |key|
322
- context key do
323
- let(:client) { Slack::RealTime::Client.new(key => 'custom') }
389
+ context key.to_s do
390
+ let(:client) { described_class.new(key => 'custom') }
391
+
324
392
  it "sets #{key}" do
325
- expect(client.send(key)).to_not eq Slack::RealTime::Config.send(key)
393
+ expect(client.send(key)).not_to eq Slack::RealTime::Config.send(key)
326
394
  expect(client.send(key)).to eq 'custom'
327
395
  end
328
396
  end
329
397
  end
330
398
  end
399
+
331
400
  describe 'logger accessor' do
332
- let(:client) { Slack::RealTime::Client.new }
401
+ let(:client) { described_class.new }
402
+
333
403
  it 'exposes public logger' do
334
404
  expect(client.logger).to be_a(::Logger)
335
405
  end
@@ -338,24 +408,30 @@ RSpec.describe Slack::RealTime::Client do
338
408
  end
339
409
  end
340
410
  end
411
+
341
412
  context 'global config' do
342
413
  after do
343
- Slack::RealTime::Client.config.reset
414
+ described_class.config.reset
344
415
  end
416
+
345
417
  let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
346
- let(:client) { Slack::RealTime::Client.new }
418
+ let(:client) { described_class.new }
419
+
347
420
  context 'ping' do
348
421
  before do
349
- Slack::RealTime::Client.configure do |config|
422
+ described_class.configure do |config|
350
423
  config.websocket_ping = 15
351
424
  end
352
425
  end
426
+
353
427
  describe '#initialize' do
354
428
  it 'sets ping' do
355
429
  expect(client.websocket_ping).to eq 15
356
430
  end
357
431
  it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
358
- expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(url, nil, ping: 15).and_return(ws)
432
+ expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
433
+ receive(:new).with(url, nil, ping: 15).and_return(ws)
434
+ )
359
435
  client.start!
360
436
  end
361
437
  it 'sets start_options' do
@@ -363,15 +439,17 @@ RSpec.describe Slack::RealTime::Client do
363
439
  end
364
440
  end
365
441
  end
442
+
366
443
  context 'proxy' do
367
444
  before do
368
- Slack::RealTime::Client.configure do |config|
445
+ described_class.configure do |config|
369
446
  config.websocket_proxy = {
370
447
  origin: 'http://username:password@proxy.example.com',
371
448
  headers: { 'User-Agent' => 'ruby' }
372
449
  }
373
450
  end
374
451
  end
452
+
375
453
  describe '#initialize' do
376
454
  it 'sets proxy' do
377
455
  expect(client.websocket_proxy).to eq(
@@ -393,40 +471,48 @@ RSpec.describe Slack::RealTime::Client do
393
471
  end
394
472
  end
395
473
  end
474
+
396
475
  context 'start_options' do
397
476
  before do
398
- Slack::RealTime::Client.configure do |config|
477
+ described_class.configure do |config|
399
478
  config.start_options = { simple_latest: true }
400
479
  end
401
480
  end
481
+
402
482
  describe '#initialize' do
403
483
  it 'sets start_options' do
404
484
  expect(client.start_options).to eq(simple_latest: true)
405
485
  end
406
486
  context 'start!' do
407
487
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
488
+
408
489
  before do
409
490
  allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
410
491
  allow(socket).to receive(:connect!)
411
492
  allow(socket).to receive(:start_sync)
412
493
  end
494
+
413
495
  it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
414
- expect(client.web_client).to receive(:rtm_start).with(simple_latest: true).and_call_original
496
+ expect(client.web_client).to(
497
+ receive(:rtm_start).with(simple_latest: true).and_call_original
498
+ )
415
499
  client.start!
416
500
  end
417
501
  end
418
502
  end
419
503
  end
504
+
420
505
  context 'store_class' do
421
506
  context 'starter' do
422
507
  before do
423
- Slack::RealTime::Client.configure do |config|
508
+ described_class.configure do |config|
424
509
  config.store_class = Slack::RealTime::Stores::Starter
425
510
  end
426
511
  end
512
+
427
513
  describe '#initialize' do
428
514
  it 'can be overriden explicitly' do
429
- client = Slack::RealTime::Client.new(store_class: Slack::RealTime::Store)
515
+ client = described_class.new(store_class: Slack::RealTime::Store)
430
516
  expect(client.send(:store_class)).to eq Slack::RealTime::Store
431
517
  end
432
518
  it 'sets store_class' do
@@ -434,11 +520,13 @@ RSpec.describe Slack::RealTime::Client do
434
520
  end
435
521
  context 'start!' do
436
522
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
523
+
437
524
  before do
438
525
  allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
439
526
  allow(socket).to receive(:connect!)
440
527
  allow(socket).to receive(:start_sync)
441
528
  end
529
+
442
530
  it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
443
531
  client.start!
444
532
  expect(client.store).to be_a Slack::RealTime::Stores::Starter
@@ -446,20 +534,24 @@ RSpec.describe Slack::RealTime::Client do
446
534
  end
447
535
  end
448
536
  end
537
+
449
538
  context 'store' do
450
539
  before do
451
- Slack::RealTime::Client.configure do |config|
540
+ described_class.configure do |config|
452
541
  config.store_class = Slack::RealTime::Stores::Store
453
542
  end
454
543
  end
544
+
455
545
  describe '#initialize' do
456
546
  context 'start!' do
457
547
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
548
+
458
549
  before do
459
550
  allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
460
551
  allow(socket).to receive(:connect!)
461
552
  allow(socket).to receive(:start_sync)
462
553
  end
554
+
463
555
  it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
464
556
  expect(client.web_client).to receive(:rtm_start).and_call_original
465
557
  client.start!
@@ -468,18 +560,20 @@ RSpec.describe Slack::RealTime::Client do
468
560
  end
469
561
  end
470
562
  end
563
+
471
564
  context 'start_method' do
472
565
  describe '#initialize' do
473
566
  it 'can be overriden explicitly' do
474
- client = Slack::RealTime::Client.new(start_method: :overriden)
567
+ client = described_class.new(start_method: :overriden)
475
568
  expect(client.send(:start_method)).to eq :overriden
476
569
  end
477
570
  context 'with start_method' do
478
571
  before do
479
- Slack::RealTime::Client.configure do |config|
572
+ described_class.configure do |config|
480
573
  config.start_method = :overriden
481
574
  end
482
575
  end
576
+
483
577
  it 'sets start_method' do
484
578
  expect(client.send(:start_method)).to eq :overriden
485
579
  end
@@ -490,14 +584,18 @@ RSpec.describe Slack::RealTime::Client do
490
584
  end.to raise_error RuntimeError, 'overriden'
491
585
  end
492
586
  end
587
+
493
588
  context 'start!' do
494
589
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
590
+
495
591
  before do
496
592
  allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
497
593
  allow(socket).to receive(:connect!)
498
594
  allow(socket).to receive(:start_sync)
499
595
  end
500
- it 'defaults to :rtm_start when using full store', vcr: { cassette_name: 'web/rtm_start' } do
596
+
597
+ it 'defaults to :rtm_start when using full store',
598
+ vcr: { cassette_name: 'web/rtm_start' } do
501
599
  expect(client.web_client).to receive(:rtm_start).and_call_original
502
600
  client.start!
503
601
  end