rspec-request_snapshot 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +2 -2
- data/README.md +13 -0
- data/lib/rspec/request_snapshot/handlers/base.rb +21 -2
- data/lib/rspec/request_snapshot/handlers/json.rb +9 -1
- data/lib/rspec/request_snapshot/matcher.rb +1 -1
- data/lib/rspec/request_snapshot/version.rb +1 -1
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f2c9dc8612a821675811ac7621e84a9da8bb54d
|
4
|
+
data.tar.gz: d09a1183cc112880e8f4fbb61fd34a6be5d6dd91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea9601e44240f191364333687fc2e3541887d01ca7e965b488d58a3ed62048747bcaa08104a338397e3fffb6101a8330d8fef2fcc5a172acf71d69971640aa10
|
7
|
+
data.tar.gz: 2f2cb89d4effa9f238d112f19743c81ec7bbef73ee55123574398130c906fb4059c8e6540019fb8eedd9357a8379e9b14a27ef5384d4b87810ae3d042e0da464
|
data/.circleci/config.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,19 @@ Notice that **all** nodes matching those (nested or not) will be ignored. Usage:
|
|
80
80
|
expect(response.body).to match_snapshot("api/resources_index", dynamic_attributes: %w(confirmed_at relation_id))
|
81
81
|
```
|
82
82
|
|
83
|
+
##### dynamic_attributes with regex
|
84
|
+
|
85
|
+
Sometimes you don't want to fully ignore an attribute. For example, you want to make sure
|
86
|
+
that `generated_id` is present and following a given pattern, but that attribute can change
|
87
|
+
randonly, use `dynamic_attributes` with object/regex notation:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# Example generated_id: ABC-001
|
91
|
+
expect(response.body).to match_snapshot("api/resources_index", dynamic_attributes: [{ generated_id: /^\w{3}-\d{3}$/ }])
|
92
|
+
```
|
93
|
+
|
94
|
+
**Note:** Partial matches are also possible, so use the start/end of line characters for a strict match
|
95
|
+
|
83
96
|
##### ignore_order
|
84
97
|
|
85
98
|
It is possible to use the `ignore_order` inline option to mark which array nodes are unsorted and that elements position
|
@@ -2,18 +2,37 @@
|
|
2
2
|
|
3
3
|
module Rspec::RequestSnapshot::Handlers
|
4
4
|
class Base
|
5
|
+
attr_reader :dynamic_attributes_with_regex
|
6
|
+
|
5
7
|
def initialize(options = {})
|
6
8
|
@options = options
|
7
9
|
end
|
8
10
|
|
9
11
|
def dynamic_attributes
|
10
|
-
@dynamic_attributes ||=
|
11
|
-
|
12
|
+
@dynamic_attributes ||= begin
|
13
|
+
list = RSpec.configuration.request_snapshots_dynamic_attributes | Array(@options[:dynamic_attributes])
|
14
|
+
strip_attributes_with_regex(list)
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def ignore_order
|
15
19
|
@ignore_order ||= RSpec.configuration.request_snapshots_ignore_order |
|
16
20
|
Array(@options[:ignore_order])
|
17
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def strip_attributes_with_regex(list)
|
26
|
+
@dynamic_attributes_with_regex = {}
|
27
|
+
list.map do |element|
|
28
|
+
if element.is_a?(String)
|
29
|
+
element
|
30
|
+
else
|
31
|
+
key = element.keys.first.to_s
|
32
|
+
@dynamic_attributes_with_regex[key] = element.values.first
|
33
|
+
key
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
@@ -18,7 +18,7 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
|
|
18
18
|
def deep_transform_values(hash)
|
19
19
|
hash.each_key do |key|
|
20
20
|
if dynamic_attributes.include?(key)
|
21
|
-
hash
|
21
|
+
handle_dynamic_attribute(hash, key)
|
22
22
|
next
|
23
23
|
end
|
24
24
|
|
@@ -42,4 +42,12 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
|
|
42
42
|
def sort_elements(hash, key)
|
43
43
|
hash[key].first.is_a?(Hash) ? hash[key].sort_by! { |e| e.keys.map { |k| e[k] } } : hash[key].sort!
|
44
44
|
end
|
45
|
+
|
46
|
+
def handle_dynamic_attribute(hash, key)
|
47
|
+
if dynamic_attributes_with_regex.key?(key)
|
48
|
+
hash[key] = dynamic_attributes_with_regex[key] if dynamic_attributes_with_regex[key].match(hash[key].to_s)
|
49
|
+
else
|
50
|
+
hash[key] = "IGNORED"
|
51
|
+
end
|
52
|
+
end
|
45
53
|
end
|
@@ -32,7 +32,7 @@ module Rspec::RequestSnapshot
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def format
|
35
|
-
@options[:format]
|
35
|
+
(@options[:format] && @options[:format].to_sym) || RSpec.configuration.request_snapshots_default_format
|
36
36
|
end
|
37
37
|
|
38
38
|
def handler
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-request_snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
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-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.16'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.16'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.16.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.16.1
|
69
69
|
description: Make sure API behavior is not changing by taking and storing a snapshot
|
@@ -74,12 +74,13 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
77
|
+
- .circleci/config.yml
|
78
|
+
- .codeclimate.yml
|
79
|
+
- .gitignore
|
80
|
+
- .rspec
|
81
|
+
- .rubocop.yml
|
82
|
+
- .ruby-version
|
83
|
+
- CHANGELOG.md
|
83
84
|
- Gemfile
|
84
85
|
- Gemfile.lock
|
85
86
|
- LICENSE.txt
|
@@ -105,17 +106,17 @@ require_paths:
|
|
105
106
|
- lib
|
106
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
108
|
requirements:
|
108
|
-
- -
|
109
|
+
- - '>='
|
109
110
|
- !ruby/object:Gem::Version
|
110
111
|
version: '0'
|
111
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
|
-
- -
|
114
|
+
- - '>='
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.0.14.1
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: Gold master testing for RSpec API request specs
|