Skip to content

Commit 8987fdc

Browse files
committed
test: isolate packaged signature loading
1 parent bfaa5d1 commit 8987fdc

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎lib/solid_objects/effect_payload.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def failure(effect_id:, arguments:, error:)
1515

1616
# @rbs (Exception) -> effect_error
1717
def error(exception)
18-
message = exception.message.to_s.byteslice(0, 8_192).to_s
18+
message = exception.message.to_s.byteslice(0, 8_192) # : String
1919
{
2020
"class" => exception.class.name,
2121
"message" => message,

‎test/integration/effect_payload_types_test.rb‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require "open3"
66
require "tmpdir"
77
require "rubygems/package"
8+
require "rubygems/installer"
89

910
class EffectPayloadTypesTest < ActiveSupport::TestCase
1011
test "packaged payload contracts check consumers and the actual constructors" do
@@ -31,7 +32,7 @@ class EffectPayloadTypesTest < ActiveSupport::TestCase
3132
configuration_path = File.join(project, "Steepfile")
3233
configuration = File.read(configuration_path)
3334
File.write(configuration_path, configuration.sub('signature "sig"', "library \"solid_objects\"\n signature \"sig/consumer.rbs\""))
34-
output, status = typecheck(project)
35+
output, status = typecheck_installed(project, package)
3536
assert status.success?, output
3637
File.write(configuration_path, configuration)
3738

@@ -81,6 +82,26 @@ def typecheck(project)
8182
[ output + error_output, status ]
8283
end
8384

85+
def typecheck_installed(project, package)
86+
gem_directory = File.join(project, "gems")
87+
specification = Gem::Installer.at(package, install_dir: gem_directory, ignore_dependencies: true).install
88+
script = <<~RUBY
89+
gem "solid_objects", #{"= #{SolidObjects::VERSION}".inspect}
90+
resolved = Gem.loaded_specs.fetch("solid_objects").full_gem_path
91+
abort "loaded signatures outside the built gem: \#{resolved}" unless resolved == #{specification.full_gem_path.inspect}
92+
load ARGV.shift
93+
RUBY
94+
output, error_output, status = Open3.capture3(
95+
{
96+
"RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil,
97+
"GEM_HOME" => gem_directory, "GEM_PATH" => ([ gem_directory ] + Gem.path).join(File::PATH_SEPARATOR)
98+
},
99+
Gem.ruby, "-e", script, Gem.bin_path("steep", "steep"), "check", "--no-daemon", "-j", "1",
100+
chdir: project
101+
)
102+
[ output + error_output, status ]
103+
end
104+
84105
def root_path(path)
85106
File.expand_path("../../#{path}", __dir__)
86107
end

0 commit comments

Comments
 (0)