rspec_approvals 0.9.2 → 0.9.3

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: 0fb4bded8ab248d2bd2826a66f0bbac01188b92614bea48bfb0203f80f118934
4
- data.tar.gz: cfaf0bea149ef3926d99f136f291b837756af97dda04d807ce47d55f57dc72a9
3
+ metadata.gz: c3ff469b7a7e1566249ed3c1c56e11121907a6a3866ad6dd5b9d754167bc8409
4
+ data.tar.gz: 63aa1daaafb280caee02bac81513adfaa2a49904c0efe7c0e8413ff47d58520e
5
5
  SHA512:
6
- metadata.gz: 041c95b54d4a62f16f0de9fb0502eb482723caca78698e7d9c0d41e5ce42031acbb59ced32bf18524962044ef3baa2daf6db0e07d5802350d13d550bd3cf3d50
7
- data.tar.gz: e77f8886c6a274455423a2ee584342a78d89a53536d75419d5965d4013d8f5166c96faadd4aec4e1980d4a0dc80c8a9cb0e1fc33d04048f62170841f911a8d26
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 : get_response
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 get_response
47
- Prompt.select "Please Choose:", 'r', menu_options
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 "!txtgrn!Approved"
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 "!txtred!Not Approved"
71
+ say 'r`Not Approved`'
73
72
  false
74
73
  end
75
74
 
76
75
  def separator
77
- "!txtgrn!" + ('_' * terminal_width)
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
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  class File
4
4
  def self.deep_write(file, content)
5
5
  dir = File.dirname file
6
- FileUtils.mkdir_p dir unless Dir.exist? dir
6
+ FileUtils.mkdir_p dir
7
7
  File.write file, content
8
8
  end
9
9
  end
@@ -25,4 +25,3 @@ unless StringIO.method_defined? :wait_readable
25
25
  end
26
26
  end
27
27
  end
28
-
@@ -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 or !interactive?
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 ->(str) do
38
+ before lambda { |str|
40
39
  str.gsub regex, replace
41
- end
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 "actual string is empty" if actual.empty?
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
@@ -7,9 +7,11 @@ module RSpecApprovals
7
7
  def match_approval(expected)
8
8
  MatchApproval.new expected
9
9
  end
10
-
10
+
11
11
  class MatchApproval < Base
12
+ def description
13
+ %[match approval "#{approval_name}"]
14
+ end
12
15
  end
13
-
14
16
  end
15
- end
17
+ 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,4 +8,4 @@ module RSpecApprovals
8
8
  @stderr ||= StringIO.new
9
9
  end
10
10
  end
11
- end
11
+ 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 ? 'txtred' : 'txtgrn'
12
- say "!#{color}!#{key}!txtrst!) #{config.first}"
11
+ color = key == default ? 'r' : 'g'
12
+ say "#{color}`#{key}`) #{config.first}"
13
13
  end
14
-
15
- say "\n!txtblu!#{prompt}!txtrst! "
16
- response = STDIN.getch.downcase
17
-
14
+
15
+ say "\nb`#{prompt}` "
16
+ response = $stdin.getch.downcase
17
+
18
18
  response = default unless options.has_key? response
19
-
20
- resay "!txtpur!#{options[response].first}"
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
@@ -19,11 +19,9 @@ module RSpecApprovals
19
19
  $stderr = RSpecApprovals.stderr
20
20
  block.call
21
21
  RSpecApprovals.send(stream).string.dup
22
-
23
22
  ensure
24
23
  $stdout = stdout_original_stream
25
24
  $stderr = stderr_original_stream
26
-
27
25
  end
28
26
  end
29
27
 
@@ -39,4 +37,4 @@ module RSpecApprovals
39
37
  end
40
38
  end
41
39
  end
42
- end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module RSpecApprovals
2
- VERSION = "0.9.2"
3
- end
2
+ VERSION = '0.9.3'
3
+ end
@@ -11,4 +11,3 @@ require 'rspec_approvals/matchers/output_approval'
11
11
  require 'rspec_approvals/matchers/raise_approval'
12
12
 
13
13
  require 'rspec_approvals/rspec_config'
14
-
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.2
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: 2021-09-03 00:00:00.000000000 Z
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: '0.5'
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: '0.5'
29
+ version: 0.8.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
27
33
  - !ruby/object:Gem::Dependency
28
- name: string-similarity
34
+ name: diffy
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '2.0'
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: '2.0'
46
+ version: '3.4'
41
47
  - !ruby/object:Gem::Dependency
42
- name: diffy
48
+ name: strings-ansi
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '3.3'
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: '3.3'
60
+ version: '0.2'
55
61
  - !ruby/object:Gem::Dependency
56
- name: strings-ansi
62
+ name: string-similarity
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0.1'
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: '0.1'
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.3.0
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.2.25
115
+ rubygems_version: 3.4.5
109
116
  signing_key:
110
117
  specification_version: 4
111
118
  summary: Interactive RSpec Approvals