Skip to content

Commit

Permalink
Merge pull request #28 from dry-rb/fix-warnings
Browse files Browse the repository at this point in the history
Fix delegation warnings
  • Loading branch information
flash-gordon authored Jan 7, 2020
2 parents 613d3dd + 6b4fc6d commit 4840d6e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 0.8.3 / 2020-01-07

## Fixed

- Delegation warnings about keyword arguments (flash-gordon)

[Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-matcher/compare/v0.8.2...v0.8.3)

# 0.8.2 / 2019-09-06

## Fixed
Expand Down
3 changes: 3 additions & 0 deletions lib/dry/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Dry
class Matcher
include Core::Constants

RUBY2_KEYWORDS = respond_to?(:ruby2_keywords, true)

# Generates a module containing pattern matching for methods listed in
# `match_methods` argument with behavior defined by `with` matcher
#
Expand Down Expand Up @@ -45,6 +47,7 @@ def self.for(*match_methods, with:)
result
end
end
ruby2_keywords(match_method) if RUBY2_KEYWORDS
end
end

Expand Down
26 changes: 24 additions & 2 deletions spec/integration/result_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
extend Dry::Monads[:result, :try]
include Dry::Monads[:result, :try]

before { Object.send(:remove_const, :Operation) if defined? Operation }

def self.set_up_expectations(matches)
matches.each do |value, matched|
context "Matching #{value}" do
Expand Down Expand Up @@ -120,8 +122,6 @@ def perform(value)
value
end
end

stub_const('Operation', Operation)
Operation.new
end

Expand All @@ -138,5 +138,27 @@ def match(value)
expect(match(Failure(:bar))).to eql('failure: bar')
end
end

context 'with keyword arguments' do
let(:operation) do
class Operation
include Dry::Matcher::ResultMatcher.for(:perform)

def perform(value:)
value
end
end
Operation.new
end

it 'works without a warning' do
result = operation.perform(value: Success(1)) do |m|
m.success { |v| v }
m.failure { raise }
end

expect(result).to be(1)
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'support/coverage'
require_relative 'support/warnings'

begin
require 'byebug'
Expand Down

0 comments on commit 4840d6e

Please sign in to comment.