ENV["RBS_TRACE"] RSpec.configure do |config| trace = RBS:#Trace.new config.before(:suite) { trace.enable } config.after(:suite) do trace.disable trace.save_comments end end end 8
do context "when args are Integer" subject { Calculator.sum(1, 2) } it { is_expected.to eq 3 } end end end class Calculator # @rbs (Integer, Integer) -" Integer def self.sum(x, y) x.to_i + y.to_i end end 14
".sum" do context "when args are Integer" subject { Calculator.sum(1, 2) } it { is_expected.to eq 3 } end context "when args are String" subject { Calculator.sum("1", "2") } it { is_expected.to eq 3 } end end end class Calculator # @rbs (Integer|String, Integer|String) -" Integer def self.sum(x, y) x.to_i + y.to_i end end 15
"#initialize" do subject { User.new(nil) } it { is_expected.to be } end end class User # @rbs (nil) -" void def initialize(name) @name = name end end 16
y) p("sum") x + y end end TracePoint.trace(:return) do |tp| p(return_value: tp.return_value, class: tp.return_value.class) end Calculator.sum(1, 2) # "sum" # {return_value: 3, class: Integer} 32
extends BasicObject • BasicObject does not have a class method class A < BasicObject end obj = A.new p(class: obj.class) # undefined method 'class' for an instance of A (NoMethodError) 35
UNBOUND_NAME = Class.instance_method(:name) TracePoint.trace(:return) do |tp| klass = UNBOUND_CLASS.bind_call(tp.return_value) class_name = UNBOUND_NAME.bind_call(klass) end 41
are as follows. 1. Method call is directly under the def keyword 2. But exclude the last method call def example foo bar buz # the return value is used end 47
config.before(:suite) { trace.enable } config.after(:suite) do trace.disable trace.save_files(out_dir: "tmp/sig-#&ENV.fetch('TEST_ENV_NUMBER', nil)}") end end 61
rbs-trace to Gemfile 2. Configure spec_helper.rb 3. Save RBS files on CI6 4. Download RBS files from CI 5. Use merge and inline commands locally 6 https://github.com/actions/upload-artifact ͳͲ 63