@@ -1136,260 +1136,6 @@ def foo(a, b, c, d, e, f, g, h); end
1136
1136
assert_success_status ( result )
1137
1137
end
1138
1138
1139
- it "must do mixin attribution properly" do
1140
- # This is pattern is taken from the private `typed_parameters` gem.
1141
- typed_parameters = mock_gem ( "typed_parameters" , "0.3.0" ) do
1142
- write! ( "lib/typed_parameters.rb" , <<~RUBY )
1143
- require "action_controller"
1144
- module TypedParameters
1145
- end
1146
- # This dynamic mixin should be generated in the gem RBI
1147
- ActionController::Parameters.include(TypedParameters)
1148
- RUBY
1149
- end
1150
-
1151
- @project . require_real_gem ( "actionpack" , "6.1.4.4" )
1152
- @project . require_mock_gem ( typed_parameters )
1153
-
1154
- @project . bundle_install!
1155
-
1156
- response = @project . tapioca ( "gem actionpack typed_parameters" )
1157
-
1158
- assert_includes ( response . out , "Compiled actionpack" )
1159
- assert_includes ( response . out , "Compiled typed_parameters" )
1160
-
1161
- actionpack_rbi = @project . read ( "sorbet/rbi/gems/[email protected] " )
1162
- # actionpack RBI should have nothing in it about `TypedParameters`
1163
- refute_includes ( actionpack_rbi , "TypedParameters" )
1164
-
1165
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1166
- # typed: true
1167
-
1168
- # DO NOT EDIT MANUALLY
1169
- # This is an autogenerated file for types exported from the `typed_parameters` gem.
1170
- # Please instead update this file by running `bin/tapioca gem typed_parameters`.
1171
-
1172
- class ActionController::Parameters
1173
- include ::TypedParameters
1174
- end
1175
-
1176
- module TypedParameters; end
1177
- RBI
1178
- end
1179
-
1180
- it "must do mixin attribution properly when include occurs in other gem" do
1181
- some_engine = mock_gem ( "some_engine" , "0.0.2" ) do
1182
- write! ( "lib/some_engine.rb" , <<~RUBY )
1183
- require "action_controller"
1184
-
1185
- module SomeEngine
1186
- class SomeController < ActionController::Base
1187
- # This method triggers a dynamic mixin which should be attributed to this gem
1188
- # and not actionpack, even though the real `include` happens inside actionpack
1189
- helper_method :foo
1190
- end
1191
- end
1192
- RUBY
1193
- end
1194
-
1195
- @project . require_real_gem ( "actionpack" , "6.1.4.4" )
1196
- @project . require_mock_gem ( some_engine )
1197
- @project . bundle_install!
1198
-
1199
- response = @project . tapioca ( "gem actionpack some_engine" )
1200
-
1201
- assert_includes ( response . out , "Compiled actionpack" )
1202
- assert_includes ( response . out , "Compiled some_engine" )
1203
-
1204
- actionpack_rbi = @project . read ( "sorbet/rbi/gems/[email protected] " )
1205
- # actionpack RBI should have nothing in it about `SomeEngine`
1206
- refute_includes ( actionpack_rbi , "SomeEngine" )
1207
-
1208
- expected = template ( <<~RBI )
1209
- # typed: true
1210
-
1211
- # DO NOT EDIT MANUALLY
1212
- # This is an autogenerated file for types exported from the `some_engine` gem.
1213
- # Please instead update this file by running `bin/tapioca gem some_engine`.
1214
-
1215
- module SomeEngine; end
1216
-
1217
- class SomeEngine::SomeController < ::ActionController::Base
1218
- private
1219
-
1220
- def _layout(lookup_context, formats); end
1221
-
1222
- class << self
1223
- def _helper_methods; end
1224
- def middleware_stack; end
1225
- end
1226
- end
1227
-
1228
- module SomeEngine::SomeController::HelperMethods
1229
- include ::ActionController::Base::HelperMethods
1230
-
1231
- <% if ruby_version(">= 3.1") %>
1232
- def foo(*args, **_arg1, &block); end
1233
- <% else %>
1234
- def foo(*args, &block); end
1235
- <% end %>
1236
- end
1237
- RBI
1238
-
1239
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , expected )
1240
- end
1241
-
1242
- it "must generate RBIs for constants defined in a different gem but with mixins in this gem" do
1243
- foo = mock_gem ( "foo" , "0.0.1" ) do
1244
- write! ( "lib/foo.rb" , <<~RBI )
1245
- class Foo
1246
- def baz; end
1247
- def buzz; end
1248
- end
1249
- RBI
1250
- end
1251
-
1252
- bar = mock_gem ( "bar" , "0.0.2" ) do
1253
- write! ( "lib/bar.rb" , <<~RBI )
1254
- module Bar; end
1255
-
1256
- Foo.prepend(Bar)
1257
- RBI
1258
- end
1259
-
1260
- @project . require_mock_gem ( foo )
1261
- @project . require_mock_gem ( bar )
1262
- @project . bundle_install!
1263
-
1264
- @project . tapioca ( "gem bar" )
1265
-
1266
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1267
- # typed: true
1268
-
1269
- # DO NOT EDIT MANUALLY
1270
- # This is an autogenerated file for types exported from the `bar` gem.
1271
- # Please instead update this file by running `bin/tapioca gem bar`.
1272
-
1273
- module Bar; end
1274
-
1275
- class Foo
1276
- include ::Bar
1277
- end
1278
- RBI
1279
- end
1280
-
1281
- it "must not generate RBIs for constants that have dynamic mixins performed in other gems" do
1282
- bar = mock_gem ( "bar" , "0.0.2" ) do
1283
- write! ( "lib/bar.rb" , <<~RBI )
1284
- module Bar; end
1285
- RBI
1286
- end
1287
-
1288
- foo = mock_gem ( "foo" , "0.0.1" ) do
1289
- write! ( "lib/foo.rb" , <<~RBI )
1290
- class Foo; end
1291
- String.prepend(Bar)
1292
- RBI
1293
- end
1294
-
1295
- @project . require_mock_gem ( bar )
1296
- @project . require_mock_gem ( foo )
1297
- @project . bundle_install!
1298
-
1299
- @project . tapioca ( "gem bar" )
1300
-
1301
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1302
- # typed: true
1303
-
1304
- # DO NOT EDIT MANUALLY
1305
- # This is an autogenerated file for types exported from the `bar` gem.
1306
- # Please instead update this file by running `bin/tapioca gem bar`.
1307
-
1308
- module Bar; end
1309
- RBI
1310
- end
1311
-
1312
- it "must generate RBIs for constants that have dynamic mixins performed in the gem" do
1313
- bar = mock_gem ( "bar" , "0.0.2" ) do
1314
- write! ( "lib/bar.rb" , <<~RBI )
1315
- class Bar
1316
- def bar; end
1317
- end
1318
- RBI
1319
- end
1320
-
1321
- foo = mock_gem ( "foo" , "0.0.1" ) do
1322
- write! ( "lib/foo.rb" , <<~RBI )
1323
- module Foo; end
1324
- class Baz < Bar; end
1325
-
1326
- Bar.prepend(Foo)
1327
- RBI
1328
- end
1329
-
1330
- @project . require_mock_gem ( bar )
1331
- @project . require_mock_gem ( foo )
1332
- @project . bundle_install!
1333
-
1334
- @project . tapioca ( "gem bar foo" )
1335
-
1336
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1337
- # typed: true
1338
-
1339
- # DO NOT EDIT MANUALLY
1340
- # This is an autogenerated file for types exported from the `foo` gem.
1341
- # Please instead update this file by running `bin/tapioca gem foo`.
1342
-
1343
- class Bar
1344
- include ::Foo
1345
- end
1346
-
1347
- class Baz < ::Bar; end
1348
- module Foo; end
1349
- RBI
1350
- end
1351
-
1352
- it "must generate RBIs for foreign constants whose singleton class overrides #inspect" do
1353
- bar = mock_gem ( "bar" , "0.0.2" ) do
1354
- write! ( "lib/bar.rb" , <<~RBI )
1355
- class Bar
1356
- def self.inspect
1357
- "Override!"
1358
- end
1359
- end
1360
- RBI
1361
- end
1362
-
1363
- foo = mock_gem ( "foo" , "0.0.1" ) do
1364
- write! ( "lib/foo.rb" , <<~RBI )
1365
- module Foo; end
1366
-
1367
- Bar.singleton_class.include(Foo)
1368
- RBI
1369
- end
1370
-
1371
- @project . require_mock_gem ( bar )
1372
- @project . require_mock_gem ( foo )
1373
- @project . bundle_install!
1374
-
1375
- result = @project . tapioca ( "gem foo" )
1376
- assert_empty_stderr ( result )
1377
-
1378
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1379
- # typed: true
1380
-
1381
- # DO NOT EDIT MANUALLY
1382
- # This is an autogenerated file for types exported from the `foo` gem.
1383
- # Please instead update this file by running `bin/tapioca gem foo`.
1384
-
1385
- class Bar
1386
- extend ::Foo
1387
- end
1388
-
1389
- module Foo; end
1390
- RBI
1391
- end
1392
-
1393
1139
it "must not load engines in the application" do
1394
1140
@project . write! ( "config/application.rb" , <<~RB )
1395
1141
require "rails"
@@ -1586,98 +1332,6 @@ class Application < Rails::Application
1586
1332
assert_includes ( turbo_streams_rbi , "module Turbo::Streams; end" )
1587
1333
assert_includes ( turbo_streams_rbi , "module Turbo::Streams::ActionHelper" )
1588
1334
end
1589
-
1590
- it "generates documentation only for the gem that defines it" do
1591
- foo = mock_gem ( "foo" , "0.0.2" ) do
1592
- write! ( "lib/foo.rb" , <<~RB )
1593
- # Most objects are cloneable
1594
- class Object
1595
- def foo; end
1596
- end
1597
- RB
1598
- end
1599
- bar = mock_gem ( "bar" , "0.0.2" ) do
1600
- write! ( "lib/bar.rb" , <<~RB )
1601
- class Object
1602
- def bar; end
1603
- end
1604
- RB
1605
- end
1606
- baz = mock_gem ( "baz" , "0.0.2" ) do
1607
- write! ( "lib/baz.rb" , <<~RB )
1608
- def baz; end
1609
- RB
1610
- end
1611
-
1612
- @project . require_mock_gem ( foo )
1613
- @project . require_mock_gem ( bar )
1614
- @project . require_mock_gem ( baz )
1615
- @project . bundle_install!
1616
-
1617
- result = @project . tapioca ( "gem bar foo baz --doc" )
1618
-
1619
- foo_rbi = @project . read ( "sorbet/rbi/gems/[email protected] " )
1620
- bar_rbi = @project . read ( "sorbet/rbi/gems/[email protected] " )
1621
- baz_rbi = @project . read ( "sorbet/rbi/gems/[email protected] " )
1622
-
1623
- documentation = <<~RBI
1624
- # Most objects are cloneable
1625
- RBI
1626
-
1627
- assert_includes ( foo_rbi , documentation )
1628
- refute_includes ( bar_rbi , documentation )
1629
- refute_includes ( baz_rbi , documentation )
1630
-
1631
- assert_empty_stderr ( result )
1632
- assert_success_status ( result )
1633
- end
1634
-
1635
- it "does not generate RBI if namespace contains alias from different gem" do
1636
- foo = mock_gem ( "foo" , "0.0.1" ) do
1637
- write! ( "lib/foo.rb" , <<~RB )
1638
- module Foo; end
1639
- F = Foo
1640
- RB
1641
- end
1642
-
1643
- bar = mock_gem ( "bar" , "0.0.1" ) do
1644
- write! ( "lib/bar.rb" , <<~RB )
1645
- module Foo
1646
- module Bar; end
1647
- end
1648
- F::B = Foo::Bar
1649
- RB
1650
- end
1651
-
1652
- @project . require_mock_gem ( foo , require : false )
1653
- @project . require_mock_gem ( bar , require : false )
1654
-
1655
- @project . bundle_install!
1656
- @project . tapioca ( "gem foo bar" )
1657
-
1658
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1659
- # typed: true
1660
-
1661
- # DO NOT EDIT MANUALLY
1662
- # This is an autogenerated file for types exported from the `foo` gem.
1663
- # Please instead update this file by running `bin/tapioca gem foo`.
1664
-
1665
- F = Foo
1666
- module Foo; end
1667
- RBI
1668
-
1669
- assert_project_file_equal ( "sorbet/rbi/gems/[email protected] " , <<~RBI )
1670
- # typed: true
1671
-
1672
- # DO NOT EDIT MANUALLY
1673
- # This is an autogenerated file for types exported from the `bar` gem.
1674
- # Please instead update this file by running `bin/tapioca gem bar`.
1675
-
1676
- module Foo; end
1677
- Foo::B = Foo::Bar
1678
- module Foo::Bar; end
1679
- RBI
1680
- end
1681
1335
end
1682
1336
1683
1337
describe "sync" do
0 commit comments