json_rspec_match_maker 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c5e58109202a9bd7a7d6f698c385606cf251c5c9c9223cfba56ab27e83e53c
|
4
|
+
data.tar.gz: c16a2b47609595be0913e35c2ce6016c041764d18786ef1657abc2da97b5776e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7afba823f316b6c071b7d5ca3ed2cd2d1c909b7a38e17fb5484152e960a4c38ae46fa5c36c04bbcb344bbad744edfac741d7317e125e5860b8459d64f365ab7
|
7
|
+
data.tar.gz: 3b1a1f3380e69441a2b9df21e4cb4fb05f3cc5c5bc8aa5523da39412d89013879718fc0f3b97d3f1511b28f0adf034dad90e3d7db0bb9e77cc72cae558563a30
|
data/Gemfile.lock
CHANGED
@@ -24,10 +24,11 @@ module JsonRspecMatchMaker
|
|
24
24
|
# @example
|
25
25
|
# JsonRspecMatchMaker.new(active_record_model)
|
26
26
|
# JsonRspecMatchMaker.new(presenter_instance)
|
27
|
-
def initialize(expected, match_definition)
|
27
|
+
def initialize(expected, match_definition, prefix: '')
|
28
28
|
@expected = expected
|
29
29
|
@match_definition = expand_definition(match_definition)
|
30
30
|
@errors = {}
|
31
|
+
@prefix = prefix
|
31
32
|
end
|
32
33
|
|
33
34
|
# Match method called by RSpec
|
@@ -126,7 +127,7 @@ module JsonRspecMatchMaker
|
|
126
127
|
# the index if iterating through a list, otherwise nil
|
127
128
|
# @return [nil] returns nothing, adds to error list as side effect
|
128
129
|
def check_values(key_prefix, error_key, match_function, expected_instance = expected)
|
129
|
-
expected_value = ExpectedValue.new(match_function, expected_instance, error_key)
|
130
|
+
expected_value = ExpectedValue.new(match_function, expected_instance, error_key, @prefix)
|
130
131
|
target_value = TargetValue.new([key_prefix, error_key].compact.join('.'), target)
|
131
132
|
add_error(expected_value, target_value) unless expected_value == target_value
|
132
133
|
end
|
@@ -4,8 +4,8 @@ module JsonRspecMatchMaker
|
|
4
4
|
# Handles fetching the expected value from the expected instance
|
5
5
|
class ExpectedValue
|
6
6
|
attr_reader :value
|
7
|
-
def initialize(match_function, expected_instance, error_key)
|
8
|
-
@value = fetch_expected_value(expected_instance, match_function, error_key)
|
7
|
+
def initialize(match_function, expected_instance, error_key, prefix)
|
8
|
+
@value = fetch_expected_value(expected_instance, match_function, error_key, prefix)
|
9
9
|
end
|
10
10
|
|
11
11
|
def ==(other)
|
@@ -15,10 +15,10 @@ module JsonRspecMatchMaker
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def fetch_expected_value(instance, function, key)
|
18
|
+
def fetch_expected_value(instance, function, key, prefix)
|
19
19
|
if function == :default
|
20
|
-
key.split('.').inject(instance) do |expected,
|
21
|
-
expected&.send
|
20
|
+
key.split('.').inject(instance) do |expected, method_name|
|
21
|
+
method_name == prefix ? expected : expected&.send(method_name)
|
22
22
|
rescue NoMethodError
|
23
23
|
nil
|
24
24
|
end
|