duck_typer 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06033bd68c3648b66718874887865c212abf0da7597d8904d511551fc2e651da
4
- data.tar.gz: 18a800f2632fe5233946b4220df58a0728a5443d63881fa08d8f1296c4455e48
3
+ metadata.gz: 2fa69aacb39291c263a7cd2d09e094ee7cf18e62f90b1148e5747f5515107c8c
4
+ data.tar.gz: dec6c2a99167fe5cdcc06e2a6d9b2a0e9c42b1898969d0637c717f7122875184
5
5
  SHA512:
6
- metadata.gz: 99787de2400a1d21667f64c981e6ad1047c866a00645ec1f2b8534c3d1a692a1204a8e6f6d422c45caca61ef17123aa814a82f046ea5848c62a6b926cf35027c
7
- data.tar.gz: 9034b7b8e3df7342e51ec9bbf1cb8cfc58d0f1f0d9d64839c53545585a2d5dfa5af0ee7c6d6cfc6fac613015ce8dfc9dbb9e5579d68ff1b607414fd608a46dbc
6
+ metadata.gz: 94070439840328f9faac3275ad69b57230981bcac9369aff4b26ee93b87cdf127e74848b7d44d4aed78bd5f37f6308ba19ec9c97a1264c86f5809db920897361
7
+ data.tar.gz: 7007b8b442e0ac7528a8aed5646d03e2e5a5256e1eb5a79a6dc20c665de1f8a9df52a29d11ab25ddc6857da9b9211f1d218ad0ab9bc2b697ef00ff475d6ddc2c
data/README.md CHANGED
@@ -77,7 +77,7 @@ class PaymentProcessorTest < Minitest::Test
77
77
  end
78
78
  ```
79
79
 
80
- To make `assert_interface_matches` available across all tests,
80
+ To make `assert_interfaces_match` available across all tests,
81
81
  require the integration in `test_helper.rb` and include the module
82
82
  in your base test class:
83
83
 
@@ -98,19 +98,19 @@ class Minitest::Test
98
98
  end
99
99
  ```
100
100
 
101
- Then use `assert_interface_matches` to assert that a list of
101
+ Then use `assert_interfaces_match` to assert that a list of
102
102
  classes share compatible interfaces:
103
103
 
104
104
  ```ruby
105
105
  def test_payment_processors_have_compatible_interfaces
106
- assert_interface_matches [StripeProcessor, PaypalProcessor, BraintreeProcessor]
106
+ assert_interfaces_match [StripeProcessor, PaypalProcessor, BraintreeProcessor]
107
107
  end
108
108
  ```
109
109
 
110
110
  The same `type:` and `methods:` options are supported:
111
111
 
112
112
  ```ruby
113
- assert_interface_matches [StripeProcessor, PaypalProcessor],
113
+ assert_interfaces_match [StripeProcessor, PaypalProcessor],
114
114
  type: :class_methods,
115
115
  methods: %i[charge refund]
116
116
  ```
@@ -157,9 +157,8 @@ by calling:
157
157
  DuckTyper::RSpec.define_shared_example
158
158
  ```
159
159
 
160
- This registers a shared example named `"an interface"`. To avoid
161
- conflicts with an existing shared example of the same name, pass
162
- a custom name:
160
+ This registers a shared example named `"an interface"`. The name
161
+ can be changed by passing a custom one:
163
162
 
164
163
  ```ruby
165
164
  DuckTyper::RSpec.define_shared_example("a compatible interface")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DuckTyper
2
4
  # Runs interface checks across all consecutive pairs of classes in a list.
3
5
  class BulkInterfaceChecker
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DuckTyper
2
4
  class InterfaceChecker
3
5
  class MethodInspector
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DuckTyper
2
4
  class InterfaceChecker
3
5
  # Normalizes method parameters to enable interface comparison. For
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DuckTyper
2
4
  class InterfaceChecker
3
5
  class Result
@@ -19,15 +21,9 @@ module DuckTyper
19
21
  Expected #{@left} and #{@right} to have compatible method \
20
22
  signatures, but the following signatures do not match:
21
23
 
22
- #{method_signatures}
24
+ #{@method_signatures.call}
23
25
  MSG
24
26
  end
25
-
26
- private
27
-
28
- def method_signatures
29
- @method_signatures.call
30
- end
31
27
  end
32
28
  end
33
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "interface_checker/result"
2
4
  require_relative "interface_checker/method_inspector"
3
5
  require_relative "interface_checker/params_normalizer"
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../duck_typer"
2
4
 
3
5
  module DuckTyper
4
6
  module Minitest
5
- def assert_interface_matches(objects, type: :instance_methods, methods: nil)
7
+ def assert_interfaces_match(objects, type: :instance_methods, methods: nil)
6
8
  checker = BulkInterfaceChecker
7
9
  .new(objects, type:, partial_interface_methods: methods)
8
10
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../duck_typer"
2
4
 
3
5
  RSpec::Matchers.define :have_matching_interfaces do |type: :instance_methods, methods: nil|
@@ -18,9 +20,20 @@ module DuckTyper
18
20
  module RSpec
19
21
  def self.define_shared_example(name = "an interface")
20
22
  ::RSpec.shared_examples name do |objects, type: :instance_methods, methods: nil|
23
+ # We intentionally avoid reusing the have_matching_interfaces matcher
24
+ # here. Since this shared example is defined in gem code, RSpec filters
25
+ # it from its backtrace, causing the Failure/Error: line to show an
26
+ # internal RSpec constant instead of useful context.
21
27
  it "has compatible interfaces" do
22
- failures = DuckTyper::BulkInterfaceChecker.new(objects, type:, partial_interface_methods: methods).call.reject(&:match?)
23
- raise ::RSpec::Expectations::ExpectationNotMetError, failures.map(&:failure_message).join("\n") if failures.any?
28
+ checker = DuckTyper::BulkInterfaceChecker
29
+ .new(objects, type:, partial_interface_methods: methods)
30
+
31
+ failures = checker.call.reject(&:match?)
32
+
33
+ if failures.any?
34
+ message = failures.map(&:failure_message).join("\n")
35
+ raise ::RSpec::Expectations::ExpectationNotMetError, message
36
+ end
24
37
  end
25
38
  end
26
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DuckTyper
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duck_typer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago A. Silva