Skip to content

Commit 8bbbea4

Browse files
committed
test: Share build results across tests to reduce build times
So far, our testcases build RBS signatures from scratch every time. It is slow and unnecessary. This introduces a mechanism to share the built signatures across tests. Before: ``` Finished in 99.189478s, 0.2016 runs/s, 0.1815 assertions/s. 20 runs, 18 assertions, 0 failures, 0 errors, 0 skips ``` After: ``` Finished in 25.321047s, 0.7899 runs/s, 0.7109 assertions/s. 20 runs, 18 assertions, 0 failures, 0 errors, 0 skips ```
1 parent cde8e4a commit 8bbbea4

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ gem 'rbs', '>= 3'
1111
gem 'rbs-inline', require: false
1212
gem 'steep', '>= 1.4'
1313
gem 'minitest'
14+
gem 'minitest-hooks'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ GEM
119119
mini_mime (1.1.5)
120120
mini_portile2 (2.8.9)
121121
minitest (5.25.5)
122+
minitest-hooks (1.5.2)
123+
minitest (> 5.3)
122124
mutex_m (0.3.0)
123125
net-imap (0.5.7)
124126
date
@@ -232,6 +234,7 @@ PLATFORMS
232234

233235
DEPENDENCIES
234236
minitest
237+
minitest-hooks
235238
rails (>= 7.0)
236239
rake (~> 13.0)
237240
rbs (>= 3)

test/rbs_rails/active_record_test.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
require 'test_helper'
22

33
class ActiveRecordTest < Minitest::Test
4-
def test_type_check
4+
include Minitest::Hooks
5+
6+
def before_all
57
clean_test_signatures
68

79
setup!
10+
end
811

9-
dir = app_dir
10-
sh!('steep', 'check', chdir: dir)
12+
def test_type_check
13+
sh!('steep', 'check', chdir: app_dir)
1114
end
1215

1316
def test_user_model_rbs_snapshot
14-
clean_test_signatures
15-
16-
setup!
17-
1817
rbs_path = app_dir.join('sig/rbs_rails/app/models/user.rbs')
1918
expect_path = expectations_dir / 'user.rbs'
2019
# Code to re-generate the expectation files
@@ -24,10 +23,6 @@ def test_user_model_rbs_snapshot
2423
end
2524

2625
def test_blog_model_rbs_snapshot
27-
clean_test_signatures
28-
29-
setup!
30-
3126
rbs_path = app_dir.join('sig/rbs_rails/packs/blogs/app/models/blog.rbs')
3227
expect_path = expectations_dir / 'blog.rbs'
3328
# Code to re-generate the expectation files
@@ -46,10 +41,6 @@ def test_article_model_rbs_is_skipped
4641
end
4742

4843
def test_external_library_model_rbs_generation
49-
clean_test_signatures
50-
51-
setup!
52-
5344
rbs_path = app_dir.join('sig/rbs_rails/app/models/audited/audit.rbs')
5445
expect_path = expectations_dir / 'audited_audit.rbs'
5546
# Code to re-generate the expectation files

test/rbs_rails/path_helper_test.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
require 'test_helper'
22

33
class PathHelperTest < Minitest::Test
4-
def test_type_check
4+
include Minitest::Hooks
5+
6+
def before_all
57
clean_test_signatures
68

79
setup!
10+
end
811

9-
dir = app_dir
10-
sh!('steep', 'check', chdir: dir)
12+
def test_type_check
13+
sh!('steep', 'check', chdir: app_dir)
1114
end
1215

1316
def test_user_model_rbs_snapshot
14-
clean_test_signatures
15-
16-
setup!
17-
1817
rbs_path = app_dir.join('sig/rbs_rails/path_helpers.rbs')
1918
expect_path = expectations_dir / 'path_helpers.rbs'
2019
# Code to re-generate the expectation files

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'minitest'
22
require 'minitest/autorun'
3+
require 'minitest/hooks'
34

45
require 'pathname'
56
require 'rbs_rails'

0 commit comments

Comments
 (0)