rspec_approvals 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec_approvals/approval_handler.rb +11 -12
- data/lib/rspec_approvals/extensions/file.rb +1 -1
- data/lib/rspec_approvals/extensions/stringio.rb +0 -1
- data/lib/rspec_approvals/matchers/base.rb +14 -16
- data/lib/rspec_approvals/matchers/match_approval.rb +5 -3
- data/lib/rspec_approvals/matchers/output_approval.rb +7 -3
- data/lib/rspec_approvals/matchers/raise_approval.rb +7 -2
- data/lib/rspec_approvals/module_functions.rb +1 -1
- data/lib/rspec_approvals/prompt.rb +9 -9
- data/lib/rspec_approvals/stream.rb +17 -18
- data/lib/rspec_approvals/version.rb +2 -2
- data/lib/rspec_approvals.rb +0 -1
- metadata +25 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ff469b7a7e1566249ed3c1c56e11121907a6a3866ad6dd5b9d754167bc8409
|
4
|
+
data.tar.gz: 63aa1daaafb280caee02bac81513adfaa2a49904c0efe7c0e8413ff47d58520e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7acae848e872e4dce5f9a3ba712c12cec05b0fdba9103c7959c9ee9eb5989d67ee34e3ad2c1c6122d8897518eb0ef533a338466ff2e8bf9f3282b8b108b1472
|
7
|
+
data.tar.gz: 4b8adb50942d8e4c4d2e5da57d8624122d9dffd72f02ad5f246d2535ca26eff3dfd827ea85f1dd35b6d30954be79eb7070ff9f3f9700cdba0f9452bf70fc46c7
|
@@ -3,7 +3,6 @@ require 'colsole'
|
|
3
3
|
require 'diffy'
|
4
4
|
|
5
5
|
module RSpecApprovals
|
6
|
-
|
7
6
|
# Handles user input and interactive approvals
|
8
7
|
class ApprovalHandler
|
9
8
|
include Colsole
|
@@ -22,7 +21,7 @@ module RSpecApprovals
|
|
22
21
|
private
|
23
22
|
|
24
23
|
def prompt_user
|
25
|
-
response = auto_approve? ? :approve :
|
24
|
+
response = auto_approve? ? :approve : user_response
|
26
25
|
|
27
26
|
case response
|
28
27
|
|
@@ -43,38 +42,38 @@ module RSpecApprovals
|
|
43
42
|
RSpec.configuration.auto_approve
|
44
43
|
end
|
45
44
|
|
46
|
-
def
|
47
|
-
Prompt.select
|
45
|
+
def user_response
|
46
|
+
Prompt.select 'Please Choose:', 'r', menu_options
|
48
47
|
end
|
49
48
|
|
50
49
|
def menu_options
|
51
50
|
base = {
|
52
51
|
'a' => ['Approve (and save)', :approve],
|
53
|
-
'r' => ['Reject (and fail test)', :reject]
|
52
|
+
'r' => ['Reject (and fail test)', :reject],
|
54
53
|
}
|
55
54
|
|
56
55
|
extra = {
|
57
56
|
'1' => ['Show actual output', :actual],
|
58
57
|
'2' => ['Show expected output', :expected],
|
59
|
-
'3' => ['Show diff', :diff]
|
58
|
+
'3' => ['Show diff', :diff],
|
60
59
|
}
|
61
60
|
|
62
|
-
expected.empty? ? base : base.merge(extra)
|
61
|
+
expected.empty? ? base : base.merge(extra)
|
63
62
|
end
|
64
63
|
|
65
64
|
def approve
|
66
|
-
say
|
65
|
+
say 'g`Approved`'
|
67
66
|
File.deep_write approval_file, actual
|
68
67
|
true
|
69
68
|
end
|
70
69
|
|
71
70
|
def reject
|
72
|
-
say
|
71
|
+
say 'r`Not Approved`'
|
73
72
|
false
|
74
73
|
end
|
75
74
|
|
76
75
|
def separator
|
77
|
-
"
|
76
|
+
"g`#{'_' * terminal_width}`"
|
78
77
|
end
|
79
78
|
|
80
79
|
def diff
|
@@ -82,10 +81,10 @@ module RSpecApprovals
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def show(what)
|
85
|
-
say
|
84
|
+
say ''
|
86
85
|
say separator
|
87
86
|
say what
|
88
87
|
say separator
|
89
88
|
end
|
90
89
|
end
|
91
|
-
end
|
90
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module RSpecApprovals
|
2
2
|
module Matchers
|
3
|
-
|
4
3
|
# A base matcher for approvals
|
5
4
|
class Base
|
6
5
|
attr_reader :approval_name, :actual, :distance, :actual_distance
|
7
6
|
|
8
|
-
def initialize(approval_name=nil)
|
7
|
+
def initialize(approval_name = nil)
|
9
8
|
@before = nil
|
10
9
|
@approval_name = approval_name
|
11
10
|
end
|
@@ -18,7 +17,7 @@ module RSpecApprovals
|
|
18
17
|
@actual = sanitize @actual
|
19
18
|
success = strings_match?
|
20
19
|
|
21
|
-
if success
|
20
|
+
if success || !interactive?
|
22
21
|
success
|
23
22
|
else
|
24
23
|
approve_approval
|
@@ -36,9 +35,9 @@ module RSpecApprovals
|
|
36
35
|
# Enables the ability to do something like:
|
37
36
|
# `expect(string).to match_approval(file).except(/\d+/)
|
38
37
|
def except(regex, replace = '...')
|
39
|
-
before
|
38
|
+
before lambda { |str|
|
40
39
|
str.gsub regex, replace
|
41
|
-
|
40
|
+
}
|
42
41
|
end
|
43
42
|
|
44
43
|
# Enables the ability to adjust the actual string before checking
|
@@ -57,10 +56,10 @@ module RSpecApprovals
|
|
57
56
|
|
58
57
|
# Called by RSpec when there is a failure
|
59
58
|
def failure_message
|
60
|
-
return
|
59
|
+
return 'actual string is empty' if actual.empty?
|
61
60
|
|
62
61
|
result = "expected: #{actual}\nto match: #{expected}"
|
63
|
-
|
62
|
+
|
64
63
|
if distance
|
65
64
|
result = "#{result}\n(actual distance is #{actual_distance} instead of the expected #{distance})"
|
66
65
|
end
|
@@ -80,7 +79,7 @@ module RSpecApprovals
|
|
80
79
|
end
|
81
80
|
|
82
81
|
# Returns true if RSpec is configured to allow interactivity.
|
83
|
-
# By default, interactivity is enabled unless the environment
|
82
|
+
# By default, interactivity is enabled unless the environment
|
84
83
|
# variable `CI` is set.
|
85
84
|
def interactive?
|
86
85
|
RSpec.configuration.interactive_approvals
|
@@ -96,7 +95,7 @@ module RSpecApprovals
|
|
96
95
|
def approval_file
|
97
96
|
"#{approvals_dir}/#{approval_name}"
|
98
97
|
end
|
99
|
-
|
98
|
+
|
100
99
|
protected
|
101
100
|
|
102
101
|
# Asks for user approval. Used by child classes.
|
@@ -110,21 +109,21 @@ module RSpecApprovals
|
|
110
109
|
File.exist?(approval_file) ? File.read(approval_file) : ''
|
111
110
|
end
|
112
111
|
|
113
|
-
# Do the actual test.
|
112
|
+
# Do the actual test.
|
114
113
|
# - If .before() was used, we foreward the actual output to the
|
115
114
|
# proc for processing first.
|
116
115
|
# - If before_approval proc was configured, forward the acual output
|
117
116
|
# to the proc for processing.
|
118
|
-
# - If .diff() was used, then distance will be set and then
|
119
|
-
# we "levenshtein it".
|
117
|
+
# - If .diff() was used, then distance will be set and then
|
118
|
+
# we "levenshtein it".
|
120
119
|
# - Otherwise, compare with ==
|
121
120
|
def strings_match?
|
122
121
|
if @before
|
123
122
|
@before.each do |proc|
|
124
|
-
@actual = proc.call actual
|
123
|
+
@actual = proc.call actual
|
125
124
|
end
|
126
125
|
end
|
127
|
-
|
126
|
+
|
128
127
|
if RSpec.configuration.before_approval.is_a? Proc
|
129
128
|
@actual = RSpec.configuration.before_approval.call actual
|
130
129
|
end
|
@@ -137,12 +136,11 @@ module RSpecApprovals
|
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
140
|
-
# Returns the input string stripped of ANSI escape codes if the
|
139
|
+
# Returns the input string stripped of ANSI escape codes if the
|
141
140
|
# strip_ansi_escape configuration setting was set to true
|
142
141
|
def sanitize(string)
|
143
142
|
sanitize? ? Strings::ANSI.sanitize(string) : string
|
144
143
|
end
|
145
144
|
end
|
146
|
-
|
147
145
|
end
|
148
146
|
end
|
@@ -5,11 +5,12 @@ module RSpecApprovals
|
|
5
5
|
def output_approval(expected)
|
6
6
|
OutputApproval.new expected
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class OutputApproval < Base
|
10
10
|
# Called by RSpec
|
11
11
|
def matches?(block)
|
12
12
|
return false unless block.is_a? Proc
|
13
|
+
|
13
14
|
@actual = stream_capturer.capture block
|
14
15
|
super
|
15
16
|
end
|
@@ -19,6 +20,10 @@ module RSpecApprovals
|
|
19
20
|
true
|
20
21
|
end
|
21
22
|
|
23
|
+
def description
|
24
|
+
%[output approval "#{approval_name}"]
|
25
|
+
end
|
26
|
+
|
22
27
|
# Adds chained matcher, to allow:
|
23
28
|
# expect { stream }.to output_approval(file).to_stdout
|
24
29
|
# This is the default, and only provided for completeness.
|
@@ -37,7 +42,6 @@ module RSpecApprovals
|
|
37
42
|
def stream_capturer
|
38
43
|
@stream_capturer ||= Stream::Stdout
|
39
44
|
end
|
40
|
-
|
41
45
|
end
|
42
46
|
end
|
43
|
-
end
|
47
|
+
end
|
@@ -5,11 +5,12 @@ module RSpecApprovals
|
|
5
5
|
def raise_approval(expected)
|
6
6
|
RaiseApproval.new expected
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
class RaiseApproval < Base
|
10
10
|
# Called by RSpec
|
11
11
|
def matches?(block)
|
12
12
|
return false unless block.is_a? Proc
|
13
|
+
|
13
14
|
@actual = 'Nothing raised'
|
14
15
|
|
15
16
|
begin
|
@@ -25,6 +26,10 @@ module RSpecApprovals
|
|
25
26
|
def supports_block_expectations?
|
26
27
|
true
|
27
28
|
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
%[raise approval "#{approval_name}"]
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
|
-
end
|
35
|
+
end
|
@@ -8,18 +8,18 @@ module RSpecApprovals
|
|
8
8
|
|
9
9
|
def select(prompt, default, options)
|
10
10
|
options.each do |key, config|
|
11
|
-
color = key == default ? '
|
12
|
-
say "
|
11
|
+
color = key == default ? 'r' : 'g'
|
12
|
+
say "#{color}`#{key}`) #{config.first}"
|
13
13
|
end
|
14
|
-
|
15
|
-
say "\
|
16
|
-
response =
|
17
|
-
|
14
|
+
|
15
|
+
say "\nb`#{prompt}` "
|
16
|
+
response = $stdin.getch.downcase
|
17
|
+
|
18
18
|
response = default unless options.has_key? response
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
say "m`#{options[response].first}`", replace: true
|
21
21
|
options[response].last
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
@@ -6,36 +6,35 @@ module RSpecApprovals
|
|
6
6
|
# These methods are borrowed from rspec's built in matchers
|
7
7
|
# https://github.com/rspec/rspec-expectations/blob/add9b271ecb1d65f7da5bc8a9dd8c64d81d92303/lib/rspec/matchers/built_in/output.rb
|
8
8
|
module Stream
|
9
|
-
module
|
10
|
-
def self.capture(block)
|
9
|
+
module Capture
|
10
|
+
def self.capture(stream, block)
|
11
11
|
RSpecApprovals.stdout.truncate 0
|
12
12
|
RSpecApprovals.stdout.rewind
|
13
|
+
RSpecApprovals.stderr.truncate 0
|
14
|
+
RSpecApprovals.stderr.rewind
|
13
15
|
|
14
|
-
|
16
|
+
stdout_original_stream = $stdout
|
17
|
+
stderr_original_stream = $stderr
|
15
18
|
$stdout = RSpecApprovals.stdout
|
19
|
+
$stderr = RSpecApprovals.stderr
|
16
20
|
block.call
|
17
|
-
RSpecApprovals.
|
18
|
-
|
21
|
+
RSpecApprovals.send(stream).string.dup
|
19
22
|
ensure
|
20
|
-
$stdout =
|
23
|
+
$stdout = stdout_original_stream
|
24
|
+
$stderr = stderr_original_stream
|
25
|
+
end
|
26
|
+
end
|
21
27
|
|
28
|
+
module Stdout
|
29
|
+
def self.capture(block)
|
30
|
+
Capture.capture :stdout, block
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
34
|
module Stderr
|
26
35
|
def self.capture(block)
|
27
|
-
|
28
|
-
RSpecApprovals.stderr.rewind
|
29
|
-
|
30
|
-
original_stream = $stderr
|
31
|
-
$stderr = RSpecApprovals.stderr
|
32
|
-
block.call
|
33
|
-
RSpecApprovals.stderr.string.dup
|
34
|
-
|
35
|
-
ensure
|
36
|
-
$stderr = original_stream
|
37
|
-
|
36
|
+
Capture.capture :stderr, block
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
41
|
-
end
|
40
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RSpecApprovals
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.9.3'
|
3
|
+
end
|
data/lib/rspec_approvals.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_approvals
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.1
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 0.8.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: diffy
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '3.4'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '3.4'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: strings-ansi
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '0.2'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '0.2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: string-similarity
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '2.1'
|
62
68
|
type: :runtime
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '2.1'
|
69
75
|
description: Automatic interactive approvals for rspec
|
70
76
|
email: db@dannyben.com
|
71
77
|
executables: []
|
@@ -89,7 +95,8 @@ files:
|
|
89
95
|
homepage: https://github.com/DannyBen/rspec_approvals
|
90
96
|
licenses:
|
91
97
|
- MIT
|
92
|
-
metadata:
|
98
|
+
metadata:
|
99
|
+
rubygems_mfa_required: 'true'
|
93
100
|
post_install_message:
|
94
101
|
rdoc_options: []
|
95
102
|
require_paths:
|
@@ -98,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
105
|
requirements:
|
99
106
|
- - ">="
|
100
107
|
- !ruby/object:Gem::Version
|
101
|
-
version: 2.
|
108
|
+
version: 2.6.0
|
102
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
110
|
requirements:
|
104
111
|
- - ">="
|
105
112
|
- !ruby/object:Gem::Version
|
106
113
|
version: '0'
|
107
114
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.4.5
|
109
116
|
signing_key:
|
110
117
|
specification_version: 4
|
111
118
|
summary: Interactive RSpec Approvals
|