simple_approvals-rspec 1.1.0 → 3.1.2

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
- SHA1:
3
- metadata.gz: c55a27cedbf93964a2c84516d1f8d1ba26db78c2
4
- data.tar.gz: 6f52c988b080e2734acefc9b36584cc12770960a
2
+ SHA256:
3
+ metadata.gz: f71df43a87b07fe15b71e6cc0c24c3482c2aff226ff36714be8a988d919edfd2
4
+ data.tar.gz: 3cfe824a91b39e426f1e101616a558c787f4104e24e8117b1707112e5f1a923c
5
5
  SHA512:
6
- metadata.gz: 7816895a44b23c16fd49ef9930ea78c706afa24f7053c0daa93728fc87e42ddb4450e853b9a449b4ca76614cb29f0f4a6666a0019fab875ea8ad3c1bb020604a
7
- data.tar.gz: a847e0f5072b1988d63770737b8b1fb09d8bc607f8f836051b2c040e573c04763295dee4dd83eaa2b1b1a79b40e054a2a98f59b4f539b8f50a65379145e590d9
6
+ metadata.gz: 25605c30b71b93bab1ededdc8ade9f8fbfefaa64c513eee4d0972792687fb399fe68cbb3287f76602bbe6b8146ac84af08be0fc11f2cd02828d87ac18a069359
7
+ data.tar.gz: 817c7d0811dfeea3e111ed9d99dd45149bb41ba72305666dff71c26d05d31c3f0a7e52f8d3eaa5cede99154b670b470ea44d12670bc36daca903e1678b24689d
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Top-level class to provide approval test support (inspired by http://approvaltests.com/)
4
2
  class Approvals
5
3
  class << self
@@ -7,33 +5,33 @@ class Approvals
7
5
  scrubbed_content = apply_optional_scrubber(rendered_content, options)
8
6
  pre_approve_if_asked(approved_path, scrubbed_content, options)
9
7
 
10
- expected_content = load_expected_content(approved_path, **options)
8
+ expected_content = load_expected_content(approved_path, options)
11
9
  received_path = received_path_for approved_path
12
10
 
13
11
  if scrubbed_content.strip.empty?
14
- raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, **options) unless options[:allow_empty]
12
+ raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options) unless options[:allow_empty]
15
13
  elsif scrubbed_content.strip == expected_content.strip
16
- handle_match(received_path, scrubbed_content, **options)
14
+ handle_match(received_path, scrubbed_content, options)
17
15
  else
18
- raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, **options)
16
+ raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options)
19
17
  end
20
18
  end
21
19
 
22
20
  private
23
21
 
24
- def apply_optional_scrubber(content, **options)
25
- if options.key?(:scrubber) && options[:scrubber]
22
+ def apply_optional_scrubber(content, options)
23
+ if options.has_key?(:scrubber) && options[:scrubber]
26
24
  options[:scrubber].call(content)
27
25
  else
28
26
  content
29
27
  end
30
28
  end
31
29
 
32
- def pre_approve_if_asked(approved_path, scrubbed_content, **options)
30
+ def pre_approve_if_asked(approved_path, scrubbed_content, options)
33
31
  File.write(approved_path, scrubbed_content) if options[:approve_all] || options[:accept_all] || ENV['APPROVE_ALL']
34
32
  end
35
33
 
36
- def handle_match(received_path, received_content, **options)
34
+ def handle_match(received_path, received_content, options)
37
35
  if options[:keep_received_file] == true
38
36
  File.write(received_path, received_content)
39
37
  elsif File.file?(received_path)
@@ -45,7 +43,7 @@ class Approvals
45
43
  "#{approved_path}.received"
46
44
  end
47
45
 
48
- def load_expected_content(approved_path, **options)
46
+ def load_expected_content(approved_path, options)
49
47
  if File.file? approved_path
50
48
  File.read(approved_path)
51
49
  else
@@ -54,7 +52,7 @@ class Approvals
54
52
  end
55
53
  end
56
54
 
57
- def raise_verify_error_with_diff(approved_path, received_path, received_content, **options)
55
+ def raise_verify_error_with_diff(approved_path, received_path, received_content, options)
58
56
  File.write(received_path, received_content)
59
57
 
60
58
  # and generate a diff for the console
@@ -63,8 +61,18 @@ class Approvals
63
61
  message << %(- writing received content to: "#{received_path}")
64
62
  message << "\n"
65
63
 
66
- expected_content = load_expected_content(approved_path)
67
- ::RSpec::Expectations.fail_with message, expected_content, received_content
64
+ expected_content = load_expected_content(approved_path, options)
65
+
66
+ if !expected_content.include?("\n") || !received_content.include?("\n")
67
+ # work around a bug in rspec-support 3.12.0's differ
68
+ # where it shows nothing when both strings are single line
69
+ # https://github.com/rspec/rspec-support/blob/v3.12.0/lib/rspec/support/differ.rb#L16-L18
70
+ message << "expected: #{expected_content.inspect}\n"
71
+ message << "received: #{received_content.inspect}\n"
72
+ ::RSpec::Expectations.fail_with message
73
+ else
74
+ ::RSpec::Expectations.fail_with message, expected_content, received_content
75
+ end
68
76
  end
69
77
  end
70
78
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'rspec/expectations'
4
2
 
5
3
  RSpec::Matchers.define :match_hash do |expected|
@@ -1,4 +1,2 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'simple_approvals/rspec/approvals'
4
2
  require 'simple_approvals/rspec/matchers'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_approvals-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Alpert
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,24 +122,23 @@ files:
122
122
  homepage: https://github.com/davidalpert/simple_approvals-rspec/
123
123
  licenses: []
124
124
  metadata: {}
125
- post_install_message:
125
+ post_install_message:
126
126
  rdoc_options: []
127
127
  require_paths:
128
128
  - lib
129
129
  required_ruby_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">="
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
- version: '0'
133
+ version: 3.1.0
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.6.11
142
- signing_key:
140
+ rubygems_version: 3.3.7
141
+ signing_key:
143
142
  specification_version: 4
144
143
  summary: ''
145
144
  test_files: []