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 +4 -4
- data/README.md +6 -7
- data/lib/duck_typer/bulk_interface_checker.rb +2 -0
- data/lib/duck_typer/interface_checker/method_inspector.rb +2 -0
- data/lib/duck_typer/interface_checker/params_normalizer.rb +2 -0
- data/lib/duck_typer/interface_checker/result.rb +3 -7
- data/lib/duck_typer/interface_checker.rb +2 -0
- data/lib/duck_typer/minitest.rb +3 -1
- data/lib/duck_typer/rspec.rb +15 -2
- data/lib/duck_typer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2fa69aacb39291c263a7cd2d09e094ee7cf18e62f90b1148e5747f5515107c8c
|
|
4
|
+
data.tar.gz: dec6c2a99167fe5cdcc06e2a6d9b2a0e9c42b1898969d0637c717f7122875184
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 `
|
|
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 `
|
|
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
|
-
|
|
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
|
-
|
|
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"`.
|
|
161
|
-
|
|
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
|
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
|
data/lib/duck_typer/minitest.rb
CHANGED
|
@@ -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
|
|
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
|
|
data/lib/duck_typer/rspec.rb
CHANGED
|
@@ -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
|
-
|
|
23
|
-
|
|
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
|
data/lib/duck_typer/version.rb
CHANGED