rspec-request_snapshot 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +29 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/lib/rspec/request_snapshot/config.rb +3 -0
- data/lib/rspec/request_snapshot/handlers/base.rb +2 -0
- data/lib/rspec/request_snapshot/handlers/json.rb +17 -9
- data/lib/rspec/request_snapshot/handlers/text.rb +2 -0
- data/lib/rspec/request_snapshot/matcher.rb +9 -7
- data/lib/rspec/request_snapshot/version.rb +5 -1
- data/lib/rspec/request_snapshot.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebce346679cd3afa78a14b57d9483e9afdfa936daa9f154324f5e4e0b46faf84
|
4
|
+
data.tar.gz: 8df3dcbfaaeff8d973c8595e91238bd361a8a740d532dc3df4a6c5aebf151c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9fa5861c5387b50d73d2348210b270282129ea7fe68825a3c6ccef21418e3df42200de04fbb2714258ccbd26fcc449216534c7ae0d16e82263056470dff489a
|
7
|
+
data.tar.gz: 63303ef240dce2b6872152903fc514297fc393004301a91e5016cc8863421dac9425750b6793cee700d60e8677bbb7fec90e6b52d60d354ac6596f99d0fa56a7
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
engines:
|
2
|
+
rubocop:
|
3
|
+
enabled: true
|
4
|
+
channel: rubocop-0-52
|
5
|
+
duplication:
|
6
|
+
enabled: true
|
7
|
+
config:
|
8
|
+
languages:
|
9
|
+
- ruby
|
10
|
+
concurrency: 1
|
11
|
+
exclude_paths:
|
12
|
+
- /spec/**/*
|
13
|
+
bundler-audit:
|
14
|
+
enabled: true
|
15
|
+
flog:
|
16
|
+
enabled: true
|
17
|
+
config:
|
18
|
+
all: false
|
19
|
+
threshold: 0.6
|
20
|
+
exclude_paths:
|
21
|
+
- /spec/**/*
|
22
|
+
ratings:
|
23
|
+
paths:
|
24
|
+
- Gemfile.lock
|
25
|
+
- "**.rb"
|
26
|
+
exclude_paths:
|
27
|
+
- /vendor/**/*
|
28
|
+
- /db/**/*
|
29
|
+
- /bin/**/*
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,10 @@ RSpec.configure do |config|
|
|
42
42
|
# The json attributes that ignore order when comparing nodes
|
43
43
|
# Default value is []
|
44
44
|
config.request_snapshots_ignore_order = %w(array_node)
|
45
|
+
|
46
|
+
# The default format to use, other formats must be specified using the :format option
|
47
|
+
# Default value is :json
|
48
|
+
config.request_snapshots_default_format = :json
|
45
49
|
end
|
46
50
|
```
|
47
51
|
|
data/Rakefile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rspec::RequestSnapshot
|
2
4
|
RSpec.configure do |config|
|
3
5
|
config.add_setting :request_snapshots_dir, default: "spec/fixtures/snapshots"
|
4
6
|
config.add_setting :request_snapshots_dynamic_attributes, default: %w(id created_at updated_at)
|
5
7
|
config.add_setting :request_snapshots_ignore_order, default: %w()
|
8
|
+
config.add_setting :request_snapshots_default_format, default: :json
|
6
9
|
end
|
7
10
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers::Base
|
2
4
|
def compare(actual, expected)
|
3
5
|
actual == expected
|
@@ -14,24 +16,30 @@ class Rspec::RequestSnapshot::Handlers::JSON < Rspec::RequestSnapshot::Handlers:
|
|
14
16
|
private
|
15
17
|
|
16
18
|
def deep_transform_values(hash)
|
17
|
-
hash.
|
19
|
+
hash.each_key do |key|
|
18
20
|
if dynamic_attributes.include?(key)
|
19
21
|
hash[key] = "REPLACED"
|
22
|
+
next
|
20
23
|
end
|
21
24
|
|
22
25
|
if hash[key].is_a?(Hash)
|
23
26
|
deep_transform_values(hash[key])
|
27
|
+
next
|
24
28
|
end
|
25
29
|
|
26
|
-
if hash[key].is_a?(Array)
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
+
deep_transform_array(hash, key) if hash[key].is_a?(Array)
|
31
|
+
end
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
34
|
+
def deep_transform_array(hash, key)
|
35
|
+
hash[key].each do |value|
|
36
|
+
deep_transform_values(value) if value.is_a?(Hash)
|
35
37
|
end
|
38
|
+
|
39
|
+
sort_elements(hash, key) if ignore_order.include?(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def sort_elements(hash, key)
|
43
|
+
hash[key].first.is_a?(Hash) ? hash[key].sort_by! { |e| e.keys.map { |k| e[k] } } : hash[key].sort!
|
36
44
|
end
|
37
45
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rspec::RequestSnapshot
|
2
4
|
RSpec::Matchers.define :match_snapshot do |snapshot_name, options|
|
3
5
|
attr_reader :actual, :expected, :options
|
@@ -7,7 +9,7 @@ module Rspec::RequestSnapshot
|
|
7
9
|
match do |actual|
|
8
10
|
@options = options || {}
|
9
11
|
|
10
|
-
snapshot_file_path = File.join(RSpec.configuration.request_snapshots_dir, "#{snapshot_name}
|
12
|
+
snapshot_file_path = File.join(RSpec.configuration.request_snapshots_dir, "#{snapshot_name}.#{format}")
|
11
13
|
|
12
14
|
FileUtils.mkdir_p(File.dirname(snapshot_file_path)) unless Dir.exist?(File.dirname(snapshot_file_path))
|
13
15
|
|
@@ -30,17 +32,17 @@ module Rspec::RequestSnapshot
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def format
|
33
|
-
@options[:format]&.to_sym ||
|
35
|
+
@options[:format]&.to_sym || RSpec.configuration.request_snapshots_default_format
|
34
36
|
end
|
35
37
|
|
36
38
|
def handler
|
37
39
|
@handler ||= begin
|
38
40
|
handler_class = case format
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
when :text
|
42
|
+
Handlers::Text
|
43
|
+
when :json
|
44
|
+
Handlers::JSON
|
45
|
+
end
|
44
46
|
handler_class.new(@options)
|
45
47
|
end
|
46
48
|
end
|
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.
|
4
|
+
version: 0.5.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-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -75,9 +75,11 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".circleci/config.yml"
|
78
|
+
- ".codeclimate.yml"
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rspec"
|
80
81
|
- ".rubocop.yml"
|
82
|
+
- ".ruby-version"
|
81
83
|
- Gemfile
|
82
84
|
- Gemfile.lock
|
83
85
|
- LICENSE.txt
|