rspec-request_snapshot 0.6.1 → 0.6.2

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
  SHA1:
3
- metadata.gz: c5bffec0454199a549825263f59398d7e9c0f47f
4
- data.tar.gz: f1f1bbf6607178b0645c96f2256379d143adedd7
3
+ metadata.gz: 064a2bd24422bf55dec9a6e2272481a14fbc8819
4
+ data.tar.gz: ad9e88a9e83e8216135d7b57d6eb7eaefadd00fb
5
5
  SHA512:
6
- metadata.gz: 10f841bec8937ad4e04ad1717c3ed438a70e9bdf446f17292fb48ecf4c9a41f987b30269b9299a3be9cd4cd610db336c06f34ee6f0192c86b321a5a1e876ee9a
7
- data.tar.gz: c969d609dbbf508d04ed51d3c57e72150914c54411ac795b9530cff145f223629d886a56409738001baf1a0e2dc743a323e6e877d2dda2b91460694d760e43cc
6
+ metadata.gz: 6773e770587d2ad04ea6d3e049d0bca8bcc9663473801aebaeb6da9701df471b8e0f3b2fc0ed83147e449c57d8e3d3a5cf6219f027ba6ac186cf9db6a181c991
7
+ data.tar.gz: 5676af26f46bf00e36b6f4edfe95b2a5490dc9a1e20cce010ee5ea7f06f2a25be9dedeff5aabf14507274a25aafc2c49327840d270be53abe2380db5007a2de4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.6.2]
4
+
5
+ ### Fixed
6
+ - Fixed issue where array responses would fail to match snapshots
7
+
3
8
  ## [v0.6.1]
4
9
 
5
10
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-request_snapshot (0.6.1)
4
+ rspec-request_snapshot (0.6.2)
5
5
  rspec (~> 3.0)
6
6
 
7
7
  GEM
@@ -15,15 +15,15 @@ GEM
15
15
  rspec-core (~> 3.8.0)
16
16
  rspec-expectations (~> 3.8.0)
17
17
  rspec-mocks (~> 3.8.0)
18
- rspec-core (3.8.0)
18
+ rspec-core (3.8.1)
19
19
  rspec-support (~> 3.8.0)
20
- rspec-expectations (3.8.3)
20
+ rspec-expectations (3.8.4)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
22
  rspec-support (~> 3.8.0)
23
- rspec-mocks (3.8.0)
23
+ rspec-mocks (3.8.1)
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
25
  rspec-support (~> 3.8.0)
26
- rspec-support (3.8.0)
26
+ rspec-support (3.8.2)
27
27
  simplecov (0.16.1)
28
28
  docile (~> 1.1)
29
29
  json (>= 1.8, < 3)
@@ -6,7 +6,7 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
6
6
  end
7
7
 
8
8
  def comparable(str)
9
- deep_transform_values(JSON.parse(str).dup)
9
+ deep_transform_json(JSON.parse(str).dup)
10
10
  end
11
11
 
12
12
  def writable(str)
@@ -15,7 +15,18 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
15
15
 
16
16
  private
17
17
 
18
- def deep_transform_values(hash)
18
+ def deep_transform_json(json)
19
+ case json
20
+ when Array
21
+ deep_transform_array(json)
22
+ when Hash
23
+ deep_transform_hash(json)
24
+ else
25
+ json
26
+ end
27
+ end
28
+
29
+ def deep_transform_hash(hash)
19
30
  hash.each_key do |key|
20
31
  if dynamic_attributes.include?(key)
21
32
  handle_dynamic_attribute(hash, key)
@@ -23,22 +34,28 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
23
34
  end
24
35
 
25
36
  if hash[key].is_a?(Hash)
26
- deep_transform_values(hash[key])
37
+ deep_transform_hash(hash[key])
27
38
  next
28
39
  end
29
40
 
30
- deep_transform_array(hash, key) if hash[key].is_a?(Array)
41
+ deep_transform_hash_array(hash, key) if hash[key].is_a?(Array)
31
42
  end
32
43
  end
33
44
 
34
- def deep_transform_array(hash, key)
45
+ def deep_transform_hash_array(hash, key)
35
46
  hash[key].each do |value|
36
- deep_transform_values(value) if value.is_a?(Hash)
47
+ deep_transform_hash(value) if value.is_a?(Hash)
37
48
  end
38
49
 
39
50
  sort_elements(hash, key) if ignore_order.include?(key)
40
51
  end
41
52
 
53
+ def deep_transform_array(array)
54
+ array.map do |element|
55
+ deep_transform_json(element)
56
+ end
57
+ end
58
+
42
59
  def sort_elements(hash, key)
43
60
  hash[key].first.is_a?(Hash) ? hash[key].sort_by! { |e| e.keys.map { |k| e[k] } } : hash[key].sort_by!(&:to_s)
44
61
  end
@@ -3,7 +3,7 @@
3
3
  # rubocop:disable Style/ClassAndModuleChildren
4
4
  module Rspec
5
5
  module RequestSnapshot
6
- VERSION = "0.6.1"
6
+ VERSION = "0.6.2"
7
7
  end
8
8
  end
9
9
  # rubocop:enable Style/ClassAndModuleChildren
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-request_snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Campos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-16 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec