rspec-match_ignoring_whitespace 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/README.md +2 -2
- data/lib/rspec/match_ignoring_whitespace.rb +68 -14
- data/lib/rspec/match_ignoring_whitespace/version.rb +1 -1
- data/rspec-match_ignoring_whitespace.gemspec +2 -0
- data/spec/match_ignoring_whitespace_spec.rb +26 -6
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '038c5481ebb263e376683226b2fd191925332aaa'
|
4
|
+
data.tar.gz: a9adcd0d707bfe6edfeb7d40c8907596410690a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af7a58d59630c3659262105e78a27eb83b976d5318a96e13f032bf9c7130a15c5ba0893479ac2c79b77fd85a82948b014b02ad325dce6ef9e8d2a7160fcc1fd9
|
7
|
+
data.tar.gz: f64cc00d6510940eb8cd4bda53c79b8ea894c3f7a6ea0dd9d32398805d538a07b08b789d6735d6b48b285e6cd9c968367990a420f8733e9d8066c00860395516
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Installation
|
|
19
19
|
Add this line to your application's Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'rspec-
|
22
|
+
gem 'rspec-match_ignoring_whitespace'
|
23
23
|
```
|
24
24
|
|
25
25
|
And then execute:
|
@@ -28,7 +28,7 @@ And then execute:
|
|
28
28
|
|
29
29
|
Or install it yourself as:
|
30
30
|
|
31
|
-
$ gem install rspec-
|
31
|
+
$ gem install rspec-match_ignoring_whitespace
|
32
32
|
|
33
33
|
|
34
34
|
Usage
|
@@ -1,30 +1,84 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'levenstein_with_path'
|
3
|
+
require 'word_wrap'
|
4
|
+
|
5
|
+
def collapse_spaces(str)
|
6
|
+
str.gsub(/[\n[[:blank:]]]+/, ' ').strip
|
7
|
+
end
|
2
8
|
|
3
9
|
RSpec::Matchers.define :match_ignoring_whitespace do |expected|
|
4
10
|
expected = expected.to_s
|
5
11
|
|
6
12
|
match do |actual|
|
7
13
|
actual = actual.to_s
|
8
|
-
actual
|
14
|
+
collapse_spaces(actual) == collapse_spaces(expected)
|
9
15
|
end
|
10
16
|
|
11
17
|
failure_message do |actual|
|
12
18
|
actual = actual.to_s
|
13
|
-
actual_normalized = actual
|
14
|
-
expected_normalized = expected
|
15
|
-
|
16
|
-
message = <<-EOF.strip
|
17
|
-
expected: #{expected_normalized.inspect}
|
18
|
-
got: #{actual_normalized.inspect}
|
19
|
-
EOF
|
20
|
-
|
21
|
-
diff = RSpec::Expectations.differ.diff(actual_normalized, expected_normalized)
|
19
|
+
actual_normalized = collapse_spaces(actual)
|
20
|
+
expected_normalized = collapse_spaces(expected)
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
diff = LevensteinWithPath::Path.new(
|
23
|
+
expected_normalized.split(' '),
|
24
|
+
actual_normalized.split(' ')
|
25
|
+
)
|
26
|
+
runs = []
|
27
|
+
last_edit = nil
|
28
|
+
diff.edits.each do |edit|
|
29
|
+
last_edit = runs.last
|
30
|
+
if last_edit.class == edit.class
|
31
|
+
runs.pop
|
32
|
+
case edit
|
33
|
+
when LevensteinWithPath::Keep
|
34
|
+
runs << LevensteinWithPath::Keep.new(last_edit.token + [edit.token])
|
35
|
+
when LevensteinWithPath::Swap
|
36
|
+
runs << LevensteinWithPath::Swap.new(last_edit.token1 + [edit.token1], last_edit.token2 + [edit.token2])
|
37
|
+
when LevensteinWithPath::Insert
|
38
|
+
runs << LevensteinWithPath::Insert.new(last_edit.token + [edit.token])
|
39
|
+
when LevensteinWithPath::Delete
|
40
|
+
runs << LevensteinWithPath::Delete.new(last_edit.token + [edit.token])
|
41
|
+
else
|
42
|
+
raise "Unknown class: #{edit}"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
case edit
|
46
|
+
when LevensteinWithPath::Keep
|
47
|
+
runs << LevensteinWithPath::Keep.new([edit.token])
|
48
|
+
when LevensteinWithPath::Swap
|
49
|
+
runs << LevensteinWithPath::Swap.new([edit.token1], [edit.token2])
|
50
|
+
when LevensteinWithPath::Insert
|
51
|
+
runs << LevensteinWithPath::Insert.new([edit.token])
|
52
|
+
when LevensteinWithPath::Delete
|
53
|
+
runs << LevensteinWithPath::Delete.new([edit.token])
|
54
|
+
else
|
55
|
+
raise "Unknown class: #{edit}"
|
56
|
+
end
|
57
|
+
end
|
26
58
|
end
|
27
59
|
|
28
|
-
message
|
60
|
+
message = runs.flat_map do |run|
|
61
|
+
case run
|
62
|
+
when LevensteinWithPath::Keep
|
63
|
+
WordWrap.ww(run.token.join(' '), 80).split("\n")
|
64
|
+
when LevensteinWithPath::Swap
|
65
|
+
WordWrap.ww(run.token1.join(' '), 78).split("\n").map do |line|
|
66
|
+
"- #{line}"
|
67
|
+
end +
|
68
|
+
WordWrap.ww(run.token2.join(' '), 78).split("\n").map do |line|
|
69
|
+
"+ #{line}"
|
70
|
+
end
|
71
|
+
when LevensteinWithPath::Insert
|
72
|
+
WordWrap.ww(run.token.join(' '), 78).split("\n").map do |line|
|
73
|
+
"+ #{line}"
|
74
|
+
end
|
75
|
+
when LevensteinWithPath::Delete
|
76
|
+
WordWrap.ww(run.token.join(' '), 78).split("\n").map do |line|
|
77
|
+
"- #{line}"
|
78
|
+
end
|
79
|
+
else
|
80
|
+
raise "Unknown class: #{run}"
|
81
|
+
end
|
82
|
+
end.join("\n")
|
29
83
|
end
|
30
84
|
end
|
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.test_files = `git ls-files -- {test,spec,fixtures}/*`.split("\n")
|
22
22
|
|
23
23
|
s.add_dependency 'rspec', '>= 3.2.0'
|
24
|
+
s.add_dependency 'levenstein_with_path'
|
25
|
+
s.add_dependency 'word_wrap'
|
24
26
|
s.add_development_dependency 'rake'
|
25
27
|
s.add_development_dependency 'bundler'
|
26
28
|
s.add_development_dependency 'simplecov'
|
@@ -43,23 +43,43 @@ describe 'match_ignoring_whitespace' do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
context "doesn't match" do
|
46
|
+
let(:matcher) { match_ignoring_whitespace(expected) }
|
46
47
|
specify 'nil' do
|
47
|
-
expect(nil).not_to
|
48
|
+
expect(nil).not_to matcher
|
49
|
+
expect(matcher.failure_message).to eq '- πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.'
|
48
50
|
end
|
49
51
|
specify 'an empty string' do
|
50
|
-
expect('').not_to
|
52
|
+
expect('').not_to matcher
|
53
|
+
expect(matcher.failure_message).to eq '- πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.'
|
51
54
|
end
|
52
55
|
specify 'a single space' do
|
53
|
-
expect(' ').not_to
|
56
|
+
expect(' ').not_to matcher
|
57
|
+
expect(matcher.failure_message).to eq '- πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.'
|
54
58
|
end
|
55
59
|
specify 'a different string' do
|
56
|
-
expect('χρημάτων ἄελπτον οὐδέν ἐστιν οὐδ᾽ ἀπώμιον οὐδὲ θαυμάσιον').not_to
|
60
|
+
expect('χρημάτων ἄελπτον οὐδέν ἐστιν οὐδ᾽ ἀπώμιον οὐδὲ θαυμάσιον').not_to matcher
|
61
|
+
expect(matcher.failure_message).to eq [
|
62
|
+
# TODO: Even Insert+Swap (like here) is joinable I think:
|
63
|
+
'+ χρημάτων',
|
64
|
+
'- πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.',
|
65
|
+
'+ ἄελπτον οὐδέν ἐστιν οὐδ᾽ ἀπώμιον οὐδὲ θαυμάσιον',
|
66
|
+
].join("\n")
|
57
67
|
end
|
58
68
|
specify 'a string missing a space' do
|
59
|
-
expect("πόλλ΄ οἶδ΄ ἀλώπηξ,ἀλλ΄ ἐχῖνος ἓν μέγα.").not_to
|
69
|
+
expect("πόλλ΄ οἶδ΄ ἀλώπηξ,ἀλλ΄ ἐχῖνος ἓν μέγα.").not_to matcher
|
70
|
+
expect(matcher.failure_message).to eq [
|
71
|
+
'πόλλ΄ οἶδ΄',
|
72
|
+
# TODO: It would be nice to join things like Delete+Swap or Swap+Insert:
|
73
|
+
'- ἀλώπηξ,',
|
74
|
+
'- ἀλλ΄',
|
75
|
+
'+ ἀλώπηξ,ἀλλ΄',
|
76
|
+
'ἐχῖνος ἓν μέγα.',
|
77
|
+
].join("\n")
|
60
78
|
end
|
61
79
|
specify 'expecting nil' do
|
62
|
-
|
80
|
+
matcher = match_ignoring_whitespace(nil)
|
81
|
+
expect('anything').not_to matcher
|
82
|
+
expect(matcher.failure_message).to eq '+ anything'
|
63
83
|
end
|
64
84
|
end
|
65
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-match_ignoring_whitespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul A. Jungwirth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: levenstein_with_path
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: word_wrap
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,8 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
149
|
version: '0'
|
122
150
|
requirements: []
|
123
151
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.6.14
|
125
153
|
signing_key:
|
126
154
|
specification_version: 4
|
127
155
|
summary: RSpec matcher to compare strings ignoring whitespace
|
128
|
-
test_files:
|
156
|
+
test_files:
|
157
|
+
- spec/match_ignoring_whitespace_spec.rb
|
158
|
+
- spec/spec_helper.rb
|