8000 Ruby 3.0 keyword arguments compatibility (pass two) by thbar · Pull Request #93 · thbar/kiba · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ruby 3.0 keyword arguments compatibility (pass two) #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
HEAD
----

- Support for Ruby 2.7+ [#93](https://github.com/thbar/kiba/pull/93). Special thanks to @eregon and @mame for their input.

3.0.0
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can also check out the [author blog](https://thibautbarrere.com) and [StackO

## Supported Ruby versions

Kiba currently supports Ruby 2.4-2.6 ([2.7 support is in preliminary tests](https://github.com/thbar/kiba/wiki/Ruby-2.7--keyword-arguments-compatibility-note)) JRuby 9.2+ and TruffleRuby. See [test matrix](https://travis-ci.org/thbar/kiba).
Kiba currently supports Ruby 2.4+, JRuby 9.2+ and TruffleRuby. See [test matrix](https://travis-ci.org/thbar/kiba).

## ETL consulting & commercial version

Expand Down
4 changes: 4 additions & 0 deletions lib/kiba/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ def destination(klass, *initialization_params)
def post_process(&block)
@control.post_processes << { block: block }
end

[:source, :transform, :destination].each do |m|
ruby2_keywords(m) if respond_to?(:ruby2_keywords, true)
end
end
end
70 changes: 70 additions & 0 deletions test/shared_runner_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,74 @@ def test_nil_transform_error_message
end
assert_raises(RuntimeError, 'Nil parameters not allowed here') { kiba_run(control) }
end

def test_ruby_3_source_kwargs
# NOTE: before Ruby 3 kwargs support, a Ruby warning would
# be captured here with Ruby 2.7 & ensure we fail,
# and an error would be raised with Ruby 2.8.0-dev
# NOTE: only the first warning will be captured, though, but
# having 3 different tests is still better
storage = nil
assert_silent do
Kiba.run(Kiba.parse do
source TestKeywordArgumentsComponent,
mandatory: "first",
on_init: -> (values) { storage = values }
end)
end
assert_equal({
mandatory: "first",
optional: nil
}, storage)
end

def test_ruby_3_transform_kwargs
storage = nil
assert_silent do
Kiba.run(Kiba.parse do
transform TestKeywordArgumentsComponent,
mandatory: "first",
on_init: -> (values) { storage = values }
end)
end
assert_equal({
mandatory: "first",
optional: nil
}, storage)
end

def test_ruby_3_destination_kwargs
storage = nil
assert_silent do
Kiba.run(Kiba.parse do
destination TestKeywordArgumentsComponent,
mandatory: "first",
on_init: -> (values) { storage = values }
end)
end
assert_equal({
mandatory: "first",
optional: nil
}, storage)
end

def test_positional_plus_keyword_arguments
storage = nil
assert_silent do
Kiba.run(Kiba.parse do
source TestMixedArgumentsComponent,
"some positional argument",
mandatory: "first",
on_init: -> (values) {
storage = values
}
end)
end

assert_equal({
some_value: "some positional argument",
mandatory: "first",
optional: nil
}, storage)
end
end
14 changes: 14 additions & 0 deletions test/support/test_keyword_arguments_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# a mock component to test Ruby 3 keyword argument support
class TestKeywordArgumentsComponent
def initialize(mandatory:, optional: nil, on_init: nil)
values = {
mandatory: mandatory,
optional: optional
}
on_init&.call(values)
end

def each
# no-op
end
end
14 changes: 14 additions & 0 deletions test/support/test_mixed_arguments_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# a mock component to test Ruby 3 keyword argument support
class TestMixedArgumentsComponent
def initialize(some_value, mandatory:, optional: nil, on_init:)
@values = {}
@values[:some_value] = some_value
@values[:mandatory] = mandatory
@values[:optional] = optional
on_init&.call(@values)
end

def each
# no-op
end
end
2 changes: 2 additions & 0 deletions test/test_streaming_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require_relative 'support/test_close_yielding_transform'
require_relative 'support/test_non_closing_transform'
require_relative 'shared_runner_tests'
require_relative 'support/test_keyword_arguments_component'
require_relative 'support/test_mixed_arguments_component'

class TestStreamingRunner < Kiba::Test
def kiba_run(job)
Expand Down
0