Skip to content

Commit

Permalink
Split async client specs. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock authored Aug 7, 2023
1 parent 6079b0f commit 3c627d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 51 deletions.
46 changes: 17 additions & 29 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-10-02 05:05:29 UTC using RuboCop version 1.26.1.
# on 2023-08-05 13:32:37 UTC using RuboCop version 1.26.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -13,10 +13,11 @@ Lint/ConstantDefinitionInBlock:
Exclude:
- 'lib/tasks/real_time.rake'

# Offense count: 1
# Offense count: 2
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/slack/real_time/concurrency/clients/async_spec.rb'
- 'spec/support/real_time/concurrency/mock.rb'

# Offense count: 1
Expand Down Expand Up @@ -46,17 +47,17 @@ Lint/RedundantCopDisableDirective:
# Offense count: 12
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 48
Max: 36

# Offense count: 4
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 14
Max: 10

# Offense count: 12
# Offense count: 13
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 32
Max: 26

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Expand All @@ -66,13 +67,7 @@ Metrics/ParameterLists:
# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 16

# Offense count: 1
# Configuration parameters: MinSize.
Performance/CollectionLiteralInLoop:
Exclude:
- 'lib/tasks/real_time.rake'
Max: 10

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Expand All @@ -86,41 +81,41 @@ Performance/StringInclude:
Exclude:
- 'lib/tasks/web.rake'

# Offense count: 3
# Offense count: 8
# This cop supports safe auto-correction (--auto-correct).
RSpec/ContextMethod:
Exclude:
- 'spec/slack/messages/formatting_spec.rb'
- 'spec/slack/web/api/mixins/users_spec.rb'

# Offense count: 74
# Offense count: 82
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 63
# Offense count: 65
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 18

# Offense count: 17
# Offense count: 19
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
# Include: **/*_spec*rb*, **/spec/**/*
RSpec/FilePath:
Enabled: false

# Offense count: 63
# Offense count: 70
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 92
# Offense count: 94
RSpec/MultipleExpectations:
Max: 5

# Offense count: 5
# Offense count: 7
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 9
Expand All @@ -131,7 +126,7 @@ RSpec/NamedSubject:
Exclude:
- 'spec/slack/web/api/mixins/conversations_list_spec.rb'

# Offense count: 44
# Offense count: 48
RSpec/NestedGroups:
Max: 6

Expand Down Expand Up @@ -177,7 +172,7 @@ Rake/Desc:
Style/FormatStringToken:
EnforcedStyle: unannotated

# Offense count: 6
# Offense count: 5
# This cop supports safe auto-correction (--auto-correct).
Style/GlobalStdStream:
Exclude:
Expand Down Expand Up @@ -211,10 +206,3 @@ Style/OptionalBooleanParameter:
Style/SlicingWithRange:
Exclude:
- 'lib/slack/web/api/mixins/ids.id.rb'

# Offense count: 1
# This cop supports unsafe auto-correction (--auto-correct-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/tasks/real_time.rake'
25 changes: 3 additions & 22 deletions spec/slack/real_time/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,54 +161,35 @@
describe '#run_handlers' do
before do
@events = client.store.class.events.dup
@async_handlers = client.async_handlers.dup
client.store.class.events.clear
end

after do
client.store.class.events.merge!(@events)
client.async_handlers = @async_handlers
end

context 'when config#async_handlers is :all', if: ENV['CONCURRENCY'] == 'async-websocket' do
context 'when config#async_handlers is :all' do
before do
@async_handlers = client.async_handlers.dup
client.async_handlers = :all
allow(socket).to receive(:run_async)
end

after do
client.async_handlers = @async_handlers
end

it 'runs tasks async' do
expect(socket).to receive(:run_async)
client.send(:run_handlers, 'example', {})
end

it 'returns an Async::Task' do
expect(client.send(:run_handlers, 'example', {})).to be_a Async::Task
end
end

context 'when config#async_handlers is :none' do
before do
@async_handlers = client.async_handlers.dup
client.async_handlers = :none
end

after do
client.async_handlers = @async_handlers
end

it 'does not run tasks async' do
expect(socket).not_to receive(:run_async)
client.send(:run_handlers, 'example', {})
end

context 'when store has no event hooks' do
it 'returns empty array of handlers, not an async task' do
expect(client.send(:run_handlers, 'example', {})).to be_empty
end
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/slack/real_time/concurrency/clients/async_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Slack::RealTime::Concurrency::Async::Socket, if: ENV['CONCURRENCY'] == 'async-websocket' do
context 'global config' do
let(:client) { described_class.new(nil) }

context 'run_async' do
it 'returns an Async::Task' do
expect(client.run_async {}).to be_a Async::Task
end
end
end
end

0 comments on commit 3c627d1

Please sign in to comment.