Skip to content

Commit

Permalink
Fixed presence tests, added code to ensure client is connectd before …
Browse files Browse the repository at this point in the history
…channel attach
  • Loading branch information
sacOO7 committed Jun 14, 2024
1 parent ea9bc6e commit 7634e6b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions spec/acceptance/realtime/presence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ def setup_test(method_name, args, options)
unless expected_state == :left
it 'raise an exception if the channel is detached' do
setup_test(method_name, args, options) do
channel_client_one.attach do
channel_client_one.transition_state_machine :detaching
channel_client_one.once(:detached) do
presence_client_one.public_send(method_name, args).tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation is not allowed when channel is in STATE.Detached/)
stop_reactor
client_one.connection.on :connected do
channel_client_one.attach do
channel_client_one.transition_state_machine :detaching
channel_client_one.once(:detached) do
presence_client_one.public_send(method_name, args).tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation is not allowed when channel is in STATE.Detached/)
stop_reactor
end
end
end
end
Expand All @@ -80,14 +82,16 @@ def setup_test(method_name, args, options)

it 'raise an exception if the channel becomes detached' do
setup_test(method_name, args, options) do
channel_client_one.attach do
channel_client_one.transition_state_machine :detaching
presence_client_one.public_send(method_name, args).tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation failed as channel transitioned to STATE.Detached/)
stop_reactor
client_one.connection.on :connected do
channel_client_one.attach do
channel_client_one.transition_state_machine :detaching
presence_client_one.public_send(method_name, args).tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation failed as channel transitioned to STATE.Detached/)
stop_reactor
end
end
end
end
Expand Down

0 comments on commit 7634e6b

Please sign in to comment.