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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9ab83e5c6e363af7b0fd232652ff9aad21a4e92be390e7b0cd14472efede05f
4
- data.tar.gz: '09680d62f5bb393fea32254078ddc280b10ee53627d7840d13fa643d84ef1572'
3
+ metadata.gz: ebce346679cd3afa78a14b57d9483e9afdfa936daa9f154324f5e4e0b46faf84
4
+ data.tar.gz: 8df3dcbfaaeff8d973c8595e91238bd361a8a740d532dc3df4a6c5aebf151c12
5
5
  SHA512:
6
- metadata.gz: 525dd5eb810666c52b50235f1cbb31311561121a80a67264d2743026adede323c6327b1eb25527776ca843b3528dce811615f0e9bdae26b3e77e583d5d22aaf7
7
- data.tar.gz: 1c2e330b6484c96d63b6f3dec4b942bd57e1f90612553b9a3cccfabca7e5796845d1296f40a1c8d4bc0eb662b8f00708095f483a04a4d2c6814122d7df17f5cf
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-request_snapshot (0.4.0)
4
+ rspec-request_snapshot (0.5.0)
5
5
  rspec (~> 3.0)
6
6
 
7
7
  GEM
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
@@ -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
  module Rspec::RequestSnapshot::Handlers
2
4
  class Base
3
5
  def initialize(options = {})
@@ -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.each do |key, value|
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
- hash[key].each do |value|
28
- deep_transform_values(value) if value.is_a?(Hash)
29
- end
30
+ deep_transform_array(hash, key) if hash[key].is_a?(Array)
31
+ end
32
+ end
30
33
 
31
- if ignore_order.include?(key)
32
- hash[key].first.is_a?(Hash) ? hash[key].sort_by! { |e| e.keys.map { |k| e[k] } } : hash[key].sort!
33
- end
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
  class Rspec::RequestSnapshot::Handlers::Text < Rspec::RequestSnapshot::Handlers::Base
2
4
  def compare(actual, expected)
3
5
  actual == expected
@@ -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}.json")
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 || :json
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
- when :text
40
- Handlers::Text
41
- when :json
42
- Handlers::JSON
43
- end
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
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Style/ClassAndModuleChildren
1
4
  module Rspec
2
5
  module RequestSnapshot
3
- VERSION = "0.4.0".freeze
6
+ VERSION = "0.5.0"
4
7
  end
5
8
  end
9
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rspec"
2
4
  require "rspec/request_snapshot/version"
3
5
  require "rspec/request_snapshot/config"
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.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-01-11 00:00:00.000000000 Z
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