Skip to content

Commit 3de4cfc

Browse files
thiagoaclaude
andcommitted
Fix shared example breaking on Ruby 3.1
On Ruby 3.1, a proc with |objects, type: :x| called with a single array argument destructures it — so objects receives the first element instead of the full array. Ruby 3.2+ changed this behavior, which is why the test was passing in CI (Ruby 3.3) but failed once we pinned the local version to the minimum required Ruby (3.1.0). Using a splat (*objects) avoids the destructuring entirely: it collects all positional arguments into an array, so objects.first is always the classes array regardless of Ruby version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 58183bf commit 3de4cfc

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lib/duck_typer/rspec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
module DuckTyper
2020
module RSpec
2121
def self.define_shared_example(name = "an interface")
22-
::RSpec.shared_examples name do |objects, type: :instance_methods, methods: nil|
22+
::RSpec.shared_examples name do |*objects, type: :instance_methods, methods: nil|
23+
objects = objects.first
2324
# We intentionally avoid reusing the have_matching_interfaces matcher
2425
# here. Since this shared example is defined in gem code, RSpec filters
2526
# it from its backtrace, causing the Failure/Error: line to show an

0 commit comments

Comments
 (0)