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: 1b5b140faa0ef46843473e4c028a1d612bfb0321cd63538d36277f97cf9b129e
4
- data.tar.gz: b59d16bc22e7f57d7f2b6fadc5faf71aaa1e2a2b0daf902ae194d656eefba551
3
+ metadata.gz: 83c5e58109202a9bd7a7d6f698c385606cf251c5c9c9223cfba56ab27e83e53c
4
+ data.tar.gz: c16a2b47609595be0913e35c2ce6016c041764d18786ef1657abc2da97b5776e
5
5
  SHA512:
6
- metadata.gz: c9f543a7915141e2faf82ba1e4da26f0c347be97ac87ec44e5c3b2635807f4e1c8b774d4d13c480d1364de61b85c1ea3248523e963a093bdcfd4c787d9c1fe41
7
- data.tar.gz: e64e5696fb2227dff2483c48dea976a9e8934aaf3bb529e776a73abc17c010d7fa2e2cfc6cf581d5bec05df24a21b4ae94aab5050cd07fb2c540c8f9d6558776
6
+ metadata.gz: a7afba823f316b6c071b7d5ca3ed2cd2d1c909b7a38e17fb5484152e960a4c38ae46fa5c36c04bbcb344bbad744edfac741d7317e125e5860b8459d64f365ab7
7
+ data.tar.gz: 3b1a1f3380e69441a2b9df21e4cb4fb05f3cc5c5bc8aa5523da39412d89013879718fc0f3b97d3f1511b28f0adf034dad90e3d7db0bb9e77cc72cae558563a30
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_rspec_match_maker (1.0.0)
4
+ json_rspec_match_maker (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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, k|
21
- expected&.send k
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonRspecMatchMaker
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_rspec_match_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGee