Skip to content

Commit c46c5d4

Browse files
committed
Simplify integration test server start.
1 parent 8e2df24 commit c46c5d4

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

spec/integration/integration_spec.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,39 @@
2929

3030
let!(:queue) { @queue = QueueWithTimeout.new }
3131

32-
def start
33-
# starts the client and pushes an item on a queue when connected
34-
client.start_async do |driver|
35-
driver.on :open do |data|
36-
logger.debug "connection.on :open, data=#{data}"
37-
queue.push :opened
38-
end
39-
40-
yield driver if block_given?
41-
end
42-
end
43-
4432
before do
4533
client.on :hello do
4634
logger.info "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
4735
end
4836

37+
client.on :message do |event|
38+
logger.info " #{event.class}"
39+
end
40+
4941
client.on :close do
5042
logger.info 'Disconnecting ...'
5143
# pushes another item to the queue when disconnected
5244
queue.push :closed
5345
end
5446
end
5547

56-
def start_server(&block)
48+
def start_server
5749
dt = rand(10..20)
5850
logger.debug "#start_server, waiting #{dt} second(s)"
5951
sleep dt # prevent Slack 429 rate limit errors
60-
# start server and wait for on :open
61-
@server = start(&block)
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
6263
logger.debug "started #{@server}"
63-
queue.pop_with_timeout(5)
64+
expect(queue.pop_with_timeout(5)).to eq :opened
6465
end
6566

6667
def wait_for_server
@@ -79,10 +80,9 @@ def wait_for_server
7980

8081
context 'client connected' do
8182
let(:channel) { "@#{client.self.id}" }
83+
let(:message) { SecureRandom.hex }
8284

8385
it 'responds to message' do
84-
message = SecureRandom.hex
85-
8686
client.on :message do |data|
8787
logger.debug data
8888
# concurrent execution of tests causes messages to arrive in any order
@@ -102,10 +102,12 @@ def wait_for_server
102102
end
103103

104104
it 'sends message' do
105-
start_server do
106-
client.message(channel: channel, text: 'Hello world!')
105+
client.on :hello do
106+
expect(client.message(channel: channel, text: message)).to be true
107107
client.stop!
108108
end
109+
110+
start_server
109111
end
110112
end
111113

0 commit comments

Comments
 (0)