Skip to content

Fix Ruby 3.0 compatibility #622

Closed
@v-kolesnikov

Description

Describe the bug

Tests don't pass on Ruby 3.0

To Reproduce

$ rvm use 3.0
$ rake spec

Expected behavior

Tests passed


Objective

ROM configuration is broken on Ruby 3.0 because of Separation of positional and keyword arguments in Ruby 3.0. It is mostly on rom-core side:
https://github.com/rom-rb/rom/blob/v5.2.5/core/lib/rom/environment.rb#L16-L53

In general all def method(*args) should be replaced to def method(*args, **kwargs), but this is not so simple in some cases (such above).

UPD:

I prepared a small proof to demonstrate the bug:

# frozen_string_literal: true

require 'bundler/inline'

gemfile(_install = true) do
  source 'https://rubygems.org'
  gem 'rom-core', '~> 5.2', '>= 5.2.4'
  gem 'rspec'
end

module MyAdapter
  class Gateway
    extend ROM::Initializer

    param :param
    option :option
  end
end

ROM.register_adapter(:my_adapter, MyAdapter)

require 'rspec/autorun'

RSpec.describe MyAdapter do
  specify do
    gw = MyAdapter::Gateway.new(:param, option: :option)
    expect(gw.param).to eq :param
    expect(gw.option).to eq :option
  end

  specify do
    conf = ROM::Configuration.new(:my_adapter, :param, option: :option)
    container = ROM.container(conf)
    gw = container.gateways[:default]
    expect(gw.param).to eq :param
    expect(gw.option).to eq :option
  end
end

On Ruby 2.7:

~/.rvm/gems/ruby-2.7.1/gems/rom-core-5.2.4/lib/rom/environment.rb:53: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
~/.rvm/gems/ruby-2.7.1/gems/rom-core-5.2.4/lib/rom/gateway.rb:83: warning: The called method `setup' is defined here
.

Finished in 0.00322 seconds (files took 0.07245 seconds to load)
2 examples, 0 failures

On Ruby 3.0:

.F

Failures:

  1) MyAdapter
     Failure/Error: conf = ROM::Configuration.new(:my_adapter, :param, option: :option)

     KeyError:
       MyAdapter::Gateway: option 'option' is required
     # (eval):6:in `block in __dry_initializer_initialize__'
     # (eval):6:in `fetch'
     # (eval):6:in `__dry_initializer_initialize__'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/dry-initializer-3.0.4/lib/dry/initializer/mixin/root.rb:7:in `initialize'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/gateway.rb:96:in `new'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/gateway.rb:96:in `setup'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:53:in `block in normalize_gateways'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:47:in `each'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:47:in `each_with_object'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:47:in `normalize_gateways'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:28:in `configure_gateways'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/environment.rb:20:in `initialize'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/configuration.rb:53:in `new'
     # /Users/b.white/.rvm/gems/ruby-3.0.0-rc1/gems/rom-core-5.2.4/lib/rom/configuration.rb:53:in `initialize'
     # rom_ruby3.rb:32:in `new'
     # rom_ruby3.rb:32:in `block (2 levels) in <main>'

Finished in 0.00311 seconds (files took 0.08745 seconds to load)
2 examples, 1 failure

Failed examples:

rspec rom_ruby3.rb:31 # MyAdapter

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions