Skip to content

Commit f31f50e

Browse files
committed
test: Share the packaged type check helpers
The telemetry type contract needs the same packaged-gem Steep check as the effect payload contract. Move the helpers into one module so both tests use them.
1 parent da1f00e commit f31f50e

2 files changed

Lines changed: 54 additions & 47 deletions

File tree

‎test/integration/effect_payload_types_test.rb‎

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# rbs_inline: enabled
22

33
require "test_helper"
4-
require "fileutils"
5-
require "open3"
64
require "tmpdir"
7-
require "rubygems/package"
8-
require "rubygems/installer"
5+
require "packaged_type_check"
96

107
class EffectPayloadTypesTest < ActiveSupport::TestCase
8+
include PackagedTypeCheck
9+
1110
test "packaged payload contracts check consumers and the actual constructors" do
1211
Dir.mktmpdir("solid-objects-effect-types") do |directory|
1312
package = build_package(directory)
@@ -74,47 +73,4 @@ class EffectPayloadTypesTest < ActiveSupport::TestCase
7473
end
7574
end
7675
end
77-
78-
private
79-
80-
def build_package(directory)
81-
artifact = File.join(directory, "solid_objects.gem")
82-
specification = Gem::Specification.load(root_path("solid_objects.gemspec"))
83-
Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do
84-
Gem::Package.build(specification, false, false, artifact)
85-
end
86-
artifact
87-
end
88-
89-
def typecheck(project)
90-
output, error_output, status = Open3.capture3(
91-
Gem.ruby, Gem.bin_path("steep", "steep"), "check", "--no-daemon", "-j", "1",
92-
chdir: project
93-
)
94-
[ output + error_output, status ]
95-
end
96-
97-
def typecheck_installed(project, package)
98-
gem_directory = File.join(project, "gems")
99-
specification = Gem::Installer.at(package, install_dir: gem_directory, ignore_dependencies: true).install
100-
script = <<~RUBY
101-
gem "solid_objects", #{"= #{SolidObjects::VERSION}".inspect}
102-
resolved = Gem.loaded_specs.fetch("solid_objects").full_gem_path
103-
abort "loaded signatures outside the built gem: \#{resolved}" unless resolved == #{specification.full_gem_path.inspect}
104-
load ARGV.shift
105-
RUBY
106-
output, error_output, status = Open3.capture3(
107-
{
108-
"RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil,
109-
"GEM_HOME" => gem_directory, "GEM_PATH" => ([ gem_directory ] + Gem.path).join(File::PATH_SEPARATOR)
110-
},
111-
Gem.ruby, "-e", script, Gem.bin_path("steep", "steep"), "check", "--no-daemon", "-j", "1",
112-
chdir: project
113-
)
114-
[ output + error_output, status ]
115-
end
116-
117-
def root_path(path)
118-
File.expand_path("../../#{path}", __dir__)
119-
end
12076
end

‎test/packaged_type_check.rb‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# rbs_inline: enabled
2+
3+
require "fileutils"
4+
require "open3"
5+
require "rubygems/package"
6+
require "rubygems/installer"
7+
8+
module PackagedTypeCheck
9+
private
10+
11+
def build_package(directory)
12+
artifact = File.join(directory, "solid_objects.gem")
13+
specification = Gem::Specification.load(root_path("solid_objects.gemspec"))
14+
Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do
15+
Gem::Package.build(specification, false, false, artifact)
16+
end
17+
artifact
18+
end
19+
20+
def typecheck(project)
21+
output, error_output, status = Open3.capture3(
22+
Gem.ruby, Gem.bin_path("steep", "steep"), "check", "--no-daemon", "-j", "1",
23+
chdir: project
24+
)
25+
[ output + error_output, status ]
26+
end
27+
28+
def typecheck_installed(project, package)
29+
gem_directory = File.join(project, "gems")
30+
specification = Gem::Installer.at(package, install_dir: gem_directory, ignore_dependencies: true).install
31+
script = <<~RUBY
32+
gem "solid_objects", #{"= #{SolidObjects::VERSION}".inspect}
33+
resolved = Gem.loaded_specs.fetch("solid_objects").full_gem_path
34+
abort "loaded signatures outside the built gem: \#{resolved}" unless resolved == #{specification.full_gem_path.inspect}
35+
load ARGV.shift
36+
RUBY
37+
output, error_output, status = Open3.capture3(
38+
{
39+
"RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil,
40+
"GEM_HOME" => gem_directory, "GEM_PATH" => ([ gem_directory ] + Gem.path).join(File::PATH_SEPARATOR)
41+
},
42+
Gem.ruby, "-e", script, Gem.bin_path("steep", "steep"), "check", "--no-daemon", "-j", "1",
43+
chdir: project
44+
)
45+
[ output + error_output, status ]
46+
end
47+
48+
def root_path(path)
49+
File.expand_path("../#{path}", __dir__)
50+
end
51+
end

0 commit comments

Comments
 (0)