Skip to content

Commit f88e56e

Browse files
committed
Sorbet issues fixed
1 parent f433241 commit f88e56e

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

lib/code_teams.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module CodeTeams
1515
class IncorrectPublicApiUsageError < StandardError; end
1616

1717
UNKNOWN_TEAM_STRING = 'Unknown Team'
18-
@plugins_registered = false
18+
@plugins_registered = T.let(false, T::Boolean)
1919

2020
sig { returns(T::Array[Team]) }
2121
def self.all
@@ -99,7 +99,7 @@ def self.register_plugins
9999
# e.g., def github (on Team)
100100
define_method(plugin.data_accessor_name) do
101101
# e.g., MyGithubPlugin.for(team).github
102-
plugin.for(self).public_send(plugin.data_accessor_name)
102+
plugin.for(T.cast(self, Team)).public_send(plugin.data_accessor_name)
103103
end
104104
end
105105
end

lib/code_teams/plugin.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Plugin
1010

1111
abstract!
1212

13+
@data_accessor_name = T.let(nil, T.nilable(String))
14+
1315
sig { params(team: Team).void }
1416
def initialize(team)
1517
@team = team

sorbet/rbi/todo.rbi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# typed: strong
55
module ::RSpec; end
66
module ::TestPlugin; end
7+
module TestNamespace::TestPlugin; end

spec/lib/plugin_spec.rb

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
RSpec.describe CodeTeams::Plugin do
2-
before do
3-
CodeTeams.bust_caches!
4-
5-
test_plugin_class = Class.new(described_class) do
6-
def extra_data
7-
@team.raw_hash['extra_data']
8-
end
9-
end
10-
stub_const('TestPlugin', test_plugin_class)
11-
end
1+
module TestNamespace; end
122

3+
RSpec.describe CodeTeams::Plugin do
134
describe '.bust_caches!' do
145
it 'clears all plugins team registries ensuring cached configs are purged' do
6+
test_plugin_class = Class.new(described_class) do
7+
def extra_data
8+
@team.raw_hash['extra_data']
9+
end
10+
end
11+
stub_const('TestNamespace::TestPlugin', test_plugin_class)
12+
13+
CodeTeams.bust_caches!
1514
write_team_yml(extra_data: true)
1615
team = CodeTeams.find('My Team')
17-
expect(TestPlugin.for(team).extra_data).to be(true)
16+
expect(TestNamespace::TestPlugin.for(team).extra_data).to be(true)
1817
write_team_yml(extra_data: false)
1918
CodeTeams.bust_caches!
2019
team = CodeTeams.find('My Team')
21-
expect(TestPlugin.for(team).extra_data).to be(false)
20+
expect(TestNamespace::TestPlugin.for(team).extra_data).to be(false)
2221
end
2322
end
2423

2524
describe '.data_accessor_name' do
2625
it 'returns the underscore version of the plugin name' do
2726
test_plugin_class = Class.new(described_class)
28-
stub_const('FooNamespace::TestPlugin', test_plugin_class)
27+
stub_const('TestNamespace::TestPlugin', test_plugin_class)
2928

30-
expect(FooNamespace::TestPlugin.data_accessor_name).to eq('test_plugin')
29+
expect(TestNamespace::TestPlugin.data_accessor_name).to eq('test_plugin')
3130
end
3231

3332
it 'can be overridden by a subclass' do
3433
test_plugin_class = Class.new(described_class) do
3534
data_accessor_name 'foo'
3635
end
37-
stub_const('TestPlugin', test_plugin_class)
36+
stub_const('TestNamespace::TestPlugin', test_plugin_class)
3837

39-
expect(TestPlugin.data_accessor_name).to eq('foo')
38+
expect(TestNamespace::TestPlugin.data_accessor_name).to eq('foo')
4039
end
4140
end
4241
end

0 commit comments

Comments
 (0)