rspec_fixtures 0.4.2 → 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: c37311a80d9a2b365aa52e88fc85889b06bff30b34d816ac751f04babb675de9
4
- data.tar.gz: 0f07c562bbc7ef087f6d7af93477b4d7a288364e62cb5e05dfa3ea1c81f712cc
3
+ metadata.gz: 52ab20de0624f17d2886b7dc0ca09dbafdbeb2ed2e09b48b9f7ac93d1bf04bdb
4
+ data.tar.gz: 9a798d88dc6e842cccf7564450e25f9252b5d4a625b20c37e04d835279136a57
5
5
  SHA512:
6
- metadata.gz: e7d76a8ef480504d15633e5b98e46f8c4a3e85cdf328433b80cf828803403121e76613dcbd2bc360e3990dd8a360ed78b6935b28e62a7ca4388f8094cfb25c0d
7
- data.tar.gz: c9efe17b0a4e6f70e680903e22c8f5546804bafa3ccb91f3ed06ae392f085369f7564944bdf2009e118e611def816c5bbdbe6d74fa96dc66a74997e9b6139251
6
+ metadata.gz: fcc930afc2eb48d158abc7d1fdafba227fd65962a20343dbfea0774639d092e9818285f4c3e6fa3b7992e77f9902d218ee2cedda8c8cf828d25c8658ea20df16
7
+ data.tar.gz: e887c4cf9d9eaeb57703163ae51b97d225957c24fbbd85e5805acff20b80383364672a85327208a95f793ab3c7427e38ff81c947fd347f369a33ef32f591624c
data/README.md CHANGED
@@ -11,7 +11,7 @@ RSpec Fixtures
11
11
  RSpec Fixtures allows you to interactively review and approve testable
12
12
  content.
13
13
 
14
- [![asciicast](https://asciinema.org/a/150733.png)](https://asciinema.org/a/150733)
14
+ ![demo](demo.gif)
15
15
 
16
16
  ---
17
17
 
@@ -1,5 +1,7 @@
1
- require 'colsole'
2
1
  require 'io/console'
2
+ require 'colsole'
3
+ require 'tty-prompt'
4
+ require 'diffy'
3
5
 
4
6
  module RSpecFixtures
5
7
 
@@ -7,36 +9,87 @@ module RSpecFixtures
7
9
  class ApprovalHandler
8
10
  include Colsole
9
11
 
12
+ attr_reader :expected, :actual, :fixture_file
13
+
10
14
  def run(expected, actual, fixture_file)
11
- line = '_' * terminal_width
15
+ @expected = expected
16
+ @actual = actual
17
+ @fixture_file = fixture_file
18
+
19
+ show expected.empty? ? actual : diff
20
+ prompt_user
21
+ end
22
+
23
+ private
24
+
25
+ def prompt_user
26
+ response = get_response
27
+
28
+ case response
29
+
30
+ when :approve, :reject
31
+ send response
32
+
33
+ when :actual, :expected, :diff
34
+ show send response
35
+ prompt_user
12
36
 
13
- say "!txtgrn!#{line}"
14
- if expected.empty?
15
- say actual
16
- else
17
- say "> Old (Fixture):"
18
- say expected
19
- say "!txtpur!#{line}"
20
- say "> New (Actual):"
21
- say actual
22
- end
23
- say "!txtgrn!#{line}"
24
- say "> Approve new fixture? (y/N): "
25
-
26
- if user_approves?
27
- say "!txtgrn!Approved"
28
- File.deep_write fixture_file, actual
29
- true
30
37
  else
31
- say "!txtred!Not Approved"
32
38
  false
39
+
33
40
  end
34
41
  end
35
42
 
36
- private
43
+ def get_response
44
+ prompt.select "Please Choose:", menu_options, marker: '>'
45
+ rescue TTY::Reader::InputInterrupt
46
+ # :nocov:
47
+ return :reject
48
+ # :nocov:
49
+ end
50
+
51
+ def menu_options
52
+ base = {
53
+ 'Reject (and fail test)' => :reject,
54
+ 'Approve (and save fixture)' => :approve,
55
+ }
56
+
57
+ extra = {
58
+ 'Show actual output' => :actual,
59
+ 'Show expected fixture' => :expected,
60
+ 'Show diff' => :diff,
61
+ }
62
+
63
+ expected.empty? ? base : base.merge(extra)
64
+ end
65
+
66
+ def approve
67
+ say "!txtgrn!Approved"
68
+ File.deep_write fixture_file, actual
69
+ true
70
+ end
71
+
72
+ def reject
73
+ say "!txtred!Not Approved"
74
+ false
75
+ end
76
+
77
+ def separator
78
+ "!txtgrn!" + ('_' * terminal_width)
79
+ end
80
+
81
+ def diff
82
+ Diffy::Diff.new(expected, actual).to_s :color
83
+ end
84
+
85
+ def show(what)
86
+ say separator
87
+ say what
88
+ say separator
89
+ end
37
90
 
38
- def user_approves?
39
- $stdin.getch =~ /[Yy]/
91
+ def prompt
92
+ @prompt ||= TTY::Prompt.new
40
93
  end
41
94
  end
42
95
  end
@@ -1,3 +1,3 @@
1
1
  module RSpecFixtures
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
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: 2018-08-04 00:00:00.000000000 Z
11
+ date: 2018-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: diffy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.17'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.17'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement