rspec_fixtures 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5a3241fd316bbe6b0a37833c5abc04a2716e9dc40e7f3925bd7f2c9b3c054c8
4
- data.tar.gz: be5e071e83a8c63702c986cc66383eba67bdf7cf17db2ae9bee626ce42a0a94d
3
+ metadata.gz: d0966017c211ac5ad38a0f4858e79b61f4ac745690dd1450f4f0e7c5a4f6375d
4
+ data.tar.gz: defcaed6913d0c75186107aa78ff701c97efdc455769ce2092a8275e439e1e46
5
5
  SHA512:
6
- metadata.gz: a7f97e03bc9bae4c1c4f327651ded29710e6fffc46b59007ede1cd894b2e62084b1fb6900cf2dc2223e030de5900ec52fa282931707ba91739cb3b58214fc6ac
7
- data.tar.gz: d9f6d87c2a9c039f12d46d33de066ef33fffef2c1c60a1a42956c208f2f87ea3d42caca10b82ba0eba06efca48a622e151b3025b258f58d09c1ae72326685774
6
+ metadata.gz: f84d5dc1c19a72554a0aa3ad6ecb2b5428267ebea79d24c9e7d64d3e1d950aae29e5304069492c498dd45a8e2661adb213b87584dc0d9999f52e458aeab59500
7
+ data.tar.gz: a8b559a243cfbe8738722fa40b2a76350eb9aac062ede216ae96dacfb8ab4ea36495ba337168051d9be74b32980072eea0c1faaadef38bc9afd31e4eb6872165
data/README.md CHANGED
@@ -82,7 +82,10 @@ expect{ $stderr.puts "hello" }.to output_fixture('fixture_filename').to_stderr
82
82
  ```
83
83
 
84
84
 
85
- ### `diff` - String Similarity
85
+ Modifiers
86
+ --------------------------------------------------
87
+
88
+ ### `diff` - String similarity
86
89
 
87
90
  Adding `diff(distance)` to either `match_fixture` or `output_fixture` will
88
91
  change the matching behavior. Instead of expecting the strings to be exactly
@@ -97,6 +100,36 @@ expect{ puts 'some string' }.to output_fixture('fixture_filename').diff(5)
97
100
  ```
98
101
 
99
102
 
103
+ ### `except` - Exclude by regular expression
104
+
105
+ Adding `except(regex)` to either `match_fixture` or `output_fixture` will
106
+ modify the string under test before runnign. The supplied regular expression
107
+ must include exactly one capture group, which will be then replaced by '...'.
108
+
109
+ In the below example, we ignore the full path of the file.
110
+
111
+ ```ruby
112
+ expect('path: /path/to/file').to match_fixture('fixture_filename').except(/path: (.*)file/)
113
+ ```
114
+
115
+ ### `before` - Alter the string before testing
116
+
117
+ The `before(proc)` method is a low level method and should normally not be
118
+ used directly (as it is used by the `except` modifier).
119
+
120
+ Adding `before(proc)` to either `match_fixture` or `output_fixture` will
121
+ call the block and supply the actual string. The proc is expected to return
122
+ the new actual string.
123
+
124
+ In the below example, we replace all email addresses in a string.
125
+
126
+ ```ruby
127
+ expect('hello rspec@fixtures.com').to match_fixture('fixture_filename').before ->(actual) do
128
+ actual.gsub /\w+@\w+\.\w+/, 'some@email.com'
129
+ end
130
+
131
+ ```
132
+
100
133
 
101
134
  Configuration
102
135
  --------------------------------------------------
@@ -31,6 +31,25 @@ module RSpecFixtures
31
31
  self
32
32
  end
33
33
 
34
+ def except(regex)
35
+ before ->(str) do
36
+ begin
37
+ str[regex, 1] = '...'
38
+ rescue IndexError
39
+ end
40
+ str
41
+ end
42
+ end
43
+
44
+ # Provides a chained matcher to adjust the actual string before
45
+ # checking for matches:
46
+ # `expect(a).to match_fixture(f).before ->(actual) { actual.gsub /one/, 'two' }`
47
+ def before(proc)
48
+ @before ||= []
49
+ @before << proc
50
+ self
51
+ end
52
+
34
53
  # Returns the expected value, from a fixture file
35
54
  def expected
36
55
  @expected ||= expected!
@@ -85,9 +104,19 @@ module RSpecFixtures
85
104
  File.exist?(fixture_file) ? File.read(fixture_file) : ''
86
105
  end
87
106
 
88
- # Do the actual test. If .diff() was used, then distance will be
89
- # set and then we "levenshtein it". Otherwise, compare with ==
107
+ # Do the actual test.
108
+ # - If .before() was used, we foreard the actual output to the
109
+ # proc for processing first.
110
+ # - If .diff() was used, then distance will be set and then
111
+ # we "levenshtein it".
112
+ # - Otherwise, compare with ==
90
113
  def strings_match?
114
+ if @before
115
+ @before.each do |proc|
116
+ @actual = proc.call actual
117
+ end
118
+ end
119
+
91
120
  if distance
92
121
  @actual_distance = String::Similarity.levenshtein_distance expected, actual
93
122
  @actual_distance <= distance
@@ -1,3 +1,3 @@
1
1
  module RSpecFixtures
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.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.5.1
4
+ version: 0.6.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-12-07 00:00:00.000000000 Z
11
+ date: 2019-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -44,112 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.2'
47
+ version: '3.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.2'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tty-prompt
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.17'
61
+ version: '0.18'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.17'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.7'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.7'
83
- - !ruby/object:Gem::Dependency
84
- name: runfile
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.9'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.9'
97
- - !ruby/object:Gem::Dependency
98
- name: runfile-tasks
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.4'
111
- - !ruby/object:Gem::Dependency
112
- name: byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '9.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '9.0'
125
- - !ruby/object:Gem::Dependency
126
- name: simplecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.14'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.14'
139
- - !ruby/object:Gem::Dependency
140
- name: yard
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '0.9'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '0.9'
68
+ version: '0.18'
153
69
  description: Automatic interactive fixtures for rspec
154
70
  email: db@dannyben.com
155
71
  executables: []
@@ -178,15 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
94
  requirements:
179
95
  - - ">="
180
96
  - !ruby/object:Gem::Version
181
- version: 2.0.0
97
+ version: 2.3.1
182
98
  required_rubygems_version: !ruby/object:Gem::Requirement
183
99
  requirements:
184
100
  - - ">="
185
101
  - !ruby/object:Gem::Version
186
102
  version: '0'
187
103
  requirements: []
188
- rubyforge_project:
189
- rubygems_version: 2.7.6
104
+ rubygems_version: 3.0.3
190
105
  signing_key:
191
106
  specification_version: 4
192
107
  summary: Interactive RSpec Fixtures