simple_approvals-rspec 1.1.1 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/simple_approvals/rspec/approvals.rb +22 -12
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58062f9d2760edfd82719892ff5cb7b859ddee062d60fe169269721f21fb12d8
|
4
|
+
data.tar.gz: 0e0ed4b8ccd440ffb9f829e1d90b9fbe3ef52fbca000b5b55eb5a152c354fa05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b1cd64285868af7604dbe14e5bbfc777987c2212617cbaa4329df897b46d77f716e4b8f0a3d77ecdcd540a4f72b29f5b6b2157f39afea1311fe620bb2c90ea7
|
7
|
+
data.tar.gz: 4f7547e83ae43ff9b8af4cad2494481358d807b96eb7a7812fd9698da983f69bffac43687a51e845889d7e041f396bbd3fe60295eeb71ce375abbf4ab78f32ed
|
@@ -5,33 +5,33 @@ class Approvals
|
|
5
5
|
scrubbed_content = apply_optional_scrubber(rendered_content, options)
|
6
6
|
pre_approve_if_asked(approved_path, scrubbed_content, options)
|
7
7
|
|
8
|
-
expected_content = load_expected_content(approved_path,
|
8
|
+
expected_content = load_expected_content(approved_path, options)
|
9
9
|
received_path = received_path_for approved_path
|
10
10
|
|
11
11
|
if scrubbed_content.strip.empty?
|
12
|
-
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content,
|
12
|
+
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options) unless options[:allow_empty]
|
13
13
|
elsif scrubbed_content.strip == expected_content.strip
|
14
|
-
handle_match(received_path, scrubbed_content,
|
14
|
+
handle_match(received_path, scrubbed_content, options)
|
15
15
|
else
|
16
|
-
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content,
|
16
|
+
raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def apply_optional_scrubber(content,
|
23
|
-
if options.
|
22
|
+
def apply_optional_scrubber(content, options)
|
23
|
+
if options.has_key?(:scrubber) && options[:scrubber]
|
24
24
|
options[:scrubber].call(content)
|
25
25
|
else
|
26
26
|
content
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def pre_approve_if_asked(approved_path, scrubbed_content,
|
30
|
+
def pre_approve_if_asked(approved_path, scrubbed_content, options)
|
31
31
|
File.write(approved_path, scrubbed_content) if options[:approve_all] || options[:accept_all] || ENV['APPROVE_ALL']
|
32
32
|
end
|
33
33
|
|
34
|
-
def handle_match(received_path, received_content,
|
34
|
+
def handle_match(received_path, received_content, options)
|
35
35
|
if options[:keep_received_file] == true
|
36
36
|
File.write(received_path, received_content)
|
37
37
|
elsif File.file?(received_path)
|
@@ -43,7 +43,7 @@ class Approvals
|
|
43
43
|
"#{approved_path}.received"
|
44
44
|
end
|
45
45
|
|
46
|
-
def load_expected_content(approved_path,
|
46
|
+
def load_expected_content(approved_path, options)
|
47
47
|
if File.file? approved_path
|
48
48
|
File.read(approved_path)
|
49
49
|
else
|
@@ -52,7 +52,7 @@ class Approvals
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def raise_verify_error_with_diff(approved_path, received_path, received_content,
|
55
|
+
def raise_verify_error_with_diff(approved_path, received_path, received_content, options)
|
56
56
|
File.write(received_path, received_content)
|
57
57
|
|
58
58
|
# and generate a diff for the console
|
@@ -61,8 +61,18 @@ class Approvals
|
|
61
61
|
message << %(- writing received content to: "#{received_path}")
|
62
62
|
message << "\n"
|
63
63
|
|
64
|
-
expected_content = load_expected_content(approved_path)
|
65
|
-
|
64
|
+
expected_content = load_expected_content(approved_path, options)
|
65
|
+
|
66
|
+
if expected_content.include?("\n") || received_content.include?("\n")
|
67
|
+
::RSpec::Expectations.fail_with message, expected_content, received_content
|
68
|
+
else
|
69
|
+
# work around a bug in rspec-support 3.12.0's differ
|
70
|
+
# where it shows nothing when both strings are single line
|
71
|
+
# https://github.com/rspec/rspec-support/blob/v3.12.0/lib/rspec/support/differ.rb#L16-L18
|
72
|
+
message << "expected: #{expected_content.inspect}\n"
|
73
|
+
message << "received: #{received_content.inspect}\n"
|
74
|
+
::RSpec::Expectations.fail_with message
|
75
|
+
end
|
66
76
|
end
|
67
77
|
end
|
68
78
|
end
|
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:
|
4
|
+
version: 3.1.3
|
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:
|
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:
|
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
|
-
|
141
|
-
|
142
|
-
signing_key:
|
140
|
+
rubygems_version: 3.3.7
|
141
|
+
signing_key:
|
143
142
|
specification_version: 4
|
144
143
|
summary: ''
|
145
144
|
test_files: []
|