rspec-match_ignoring_whitespace 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad3b8354fd617b6a2db5a077cfa3b1c49ab2394f6d481e722d5158013ae378b7
4
+ data.tar.gz: acfabac792eee53f6f9f7ec4ee1c19498815a3e7524553fe1735845e9931f398
5
+ SHA512:
6
+ metadata.gz: bebec84b9e47ae4b9db953703125bc23e017a5bdd3ae90ce6724b207bc9c48fd3c7df8c61d546a66fc651a4c95a755dc9f6eee860c41ac137779259746c93c90
7
+ data.tar.gz: 72a52d8d2b77a41d27ba668cb8d59769de5d2c329e06def7503b3ea28a3530e69f36c68dcb26c430fa9021b3fc6206e8950dd9c5d3f0d72c603eac641f0a5e21
@@ -0,0 +1,9 @@
1
+ .*.swp
2
+ .*.swo
3
+ /.ruby-version
4
+ /.ruby-gemset
5
+ /pkg
6
+ /tmp
7
+ /README.html
8
+ /coverage
9
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,43 @@
1
+ Metrics/BlockLength:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Exclude:
5
+ - "Rakefile"
6
+ Max: 120
7
+
8
+ Metrics/MethodLength:
9
+ Exclude:
10
+ - "spec/**/*"
11
+ Max: 35
12
+ Style/BlockDelimiters:
13
+ EnforcedStyle: line_count_based
14
+ Exclude:
15
+ - "spec/**/*"
16
+
17
+ Style/Documentation:
18
+ Exclude:
19
+ - "spec/**/*"
20
+ Style/PercentLiteralDelimiters:
21
+ PreferredDelimiters:
22
+ "%w": "[]"
23
+
24
+ Style/StringLiterals:
25
+ Enabled: false
26
+
27
+ Style/ExpandPathArguments:
28
+ Enabled: false
29
+
30
+ Gemspec/OrderedDependencies:
31
+ Enabled: false
32
+
33
+ Naming/HeredocDelimiterNaming:
34
+ Enabled: false
35
+
36
+ Layout/EmptyLinesAroundBlockBody:
37
+ Enabled: false
38
+
39
+ Layout/IndentHeredoc:
40
+ Enabled: false
41
+
42
+ Style/Encoding:
43
+ Enabled: false
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ - jruby
11
+
12
+ matrix:
13
+ include:
14
+ # Only run rubocop on the latest Ruby:
15
+ - rvm: 2.5
16
+ env: SUITE="rubocop"
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Paul A. Jungwirth
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ rspec-match_ignoring_whitespace
2
+ ===============================
3
+
4
+ [![Build Status](https://travis-ci.org/pjungwir/rspec-match_ignoring_whitespace.svg?branch=master)](https://travis-ci.org/pjungwir/rspec-match_ignoring_whitespace)
5
+
6
+ RSpec matcher to compare strings ignoring (most) whitespace.
7
+
8
+ First we convert all adjacent whitespace to a single space, including tabs, newlines, form feeds, non-breaking spaces, etc.
9
+ Then we also strip whitespace from the beginning and end.
10
+ Finally we compare the results for equality.
11
+
12
+ This gem borrows almost everything from [`rspec-match_fuzzy`](https://github.com/winebarrel/rspec-match_fuzzy/),
13
+ except the comparison algorithm is just a bit different.
14
+
15
+
16
+ Installation
17
+ ------------
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'rspec-match_fuzzy'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install rspec-match_fuzzy
32
+
33
+
34
+ Usage
35
+ -----
36
+
37
+ ```ruby
38
+ s1 = "πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα."
39
+ s2 = <<-EOF
40
+ πόλλ΄ οἶδ΄ ἀλώπηξ,
41
+ ἀλλ΄ ἐχῖνος ἓν μέγα.
42
+ EOF
43
+ expect(s1).to match_ignoring_whitespace(s2)
44
+ ```
45
+
46
+
47
+ TODO
48
+ ----
49
+
50
+ I can imagine a few variations of our comparison algorithm being useful:
51
+
52
+ - Instead of replacing whitespace with a single space, just remove it completely.
53
+ - Don't strip off the leading/trailing space.
54
+
55
+ If anyone out there wants those features, let me know! :-)
56
+
57
+
58
+ Tests
59
+ -----
60
+
61
+ Say `rake` to run rspec tests plus Rubocop,
62
+ or `rspec spec` to run just the tests.
63
+
64
+
65
+ Contributing
66
+ ------------
67
+
68
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
69
+ * Check out the issue tracker to make sure someone hasn't already requested and/or contributed it.
70
+ * Fork the project.
71
+ * Start a feature/bugfix branch.
72
+ * Commit and push until you are happy with your contribution.
73
+ * Make be sure to add tests for it. This is important so I don't break it in a future version unintentionally.
74
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, that is fine, but please isolate that change to its own commit so I can cherry-pick around it.
75
+
76
+ Commands for building/releasing/installing:
77
+
78
+ * `rake build`
79
+ * `rake install`
80
+ * `rake release`
81
+
82
+ Copyright
83
+ ---------
84
+
85
+ Copyright (c) 2018 Paul A. Jungwirth.
86
+ See LICENSE.txt for further details.
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task readme: [] do
9
+ system %q{jq --slurp --raw-input '{"text": "\(.)", "mode": "gfm", "context": "pjungwir/rspec-match_ignoring_whitespace"}' < README.md | curl --data @- https://api.github.com/markdown > README.html}
10
+ end
11
+
12
+ if ENV['CI'].nil?
13
+ task default: %w[spec rubocop]
14
+ else
15
+ case ENV['SUITE']
16
+ when 'rubocop' then task default: :rubocop
17
+ else task default: :spec
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ require 'rspec'
2
+
3
+ RSpec::Matchers.define :match_ignoring_whitespace do |expected|
4
+ expected = expected.to_s
5
+
6
+ match do |actual|
7
+ actual = actual.to_s
8
+ actual.gsub(/[\n[[:blank:]]]+/, ' ').strip == expected.gsub(/[\n[[:blank:]]]+/, ' ').strip
9
+ end
10
+
11
+ failure_message do |actual|
12
+ actual = actual.to_s
13
+ actual_normalized = actual.gsub(/[\n[[:blank:]]]+/, ' ').strip
14
+ expected_normalized = expected.gsub(/[\n[[:blank:]]]+/, ' ').strip
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)
22
+
23
+ unless diff.strip.empty?
24
+ diff_label = RSpec::Matchers::ExpectedsForMultipleDiffs::DEFAULT_DIFF_LABEL
25
+ message << "\n\n" << diff_label << diff
26
+ end
27
+
28
+ message
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module MatchIgnoringWhitespace
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rspec/match_ignoring_whitespace/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rspec-match_ignoring_whitespace'
7
+ s.version = RSpec::MatchIgnoringWhitespace::VERSION
8
+
9
+ s.summary = 'RSpec matcher to compare strings ignoring whitespace'
10
+ s.description = 'RSpec matcher to compare strings ignoring whitespace'
11
+
12
+ s.authors = ['Paul A. Jungwirth']
13
+ s.homepage = 'https://github.com/pjungwir/rspec-match_ignoring_whitespace'
14
+ s.email = ['pj@illuminatedcomputing.com']
15
+
16
+ s.licenses = ['MIT']
17
+
18
+ s.require_paths = ['lib']
19
+ s.executables = []
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,fixtures}/*`.split("\n")
22
+
23
+ s.add_dependency 'rspec', '>= 3.2.0'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'bundler'
26
+ s.add_development_dependency 'simplecov'
27
+ s.add_development_dependency 'rubocop'
28
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ describe 'match_ignoring_whitespace' do
4
+
5
+ let(:expected) { "πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα." }
6
+
7
+ context "matches" do
8
+ specify 'an identical string' do
9
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
10
+ end
11
+ specify 'a string with newlines' do
12
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ,\nἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
13
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ,\n\nἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
14
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, \nἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
15
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, \n ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
16
+ end
17
+ specify 'a string with leading whitespace' do
18
+ expect(" πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
19
+ expect(" πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
20
+ expect("\tπόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
21
+ expect("\nπόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
22
+ expect("\n\nπόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
23
+ expect("\t πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
24
+ expect(" \tπόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
25
+ end
26
+ specify 'a string with trailing whitespace' do
27
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα. ").to match_ignoring_whitespace expected
28
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα. ").to match_ignoring_whitespace expected
29
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.\t").to match_ignoring_whitespace expected
30
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.\n").to match_ignoring_whitespace expected
31
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.\n\n").to match_ignoring_whitespace expected
32
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.\t ").to match_ignoring_whitespace expected
33
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα. \t").to match_ignoring_whitespace expected
34
+ end
35
+ specify 'a string with extra whitespace' do
36
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
37
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
38
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ, \t ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
39
+ end
40
+ specify 'a string with a non-breaking space' do
41
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ,\u{00a0}ἀλλ΄ ἐχῖνος ἓν μέγα.").to match_ignoring_whitespace expected
42
+ end
43
+ end
44
+
45
+ context "doesn't match" do
46
+ specify 'nil' do
47
+ expect(nil).not_to match_ignoring_whitespace expected
48
+ end
49
+ specify 'an empty string' do
50
+ expect('').not_to match_ignoring_whitespace expected
51
+ end
52
+ specify 'a single space' do
53
+ expect(' ').not_to match_ignoring_whitespace expected
54
+ end
55
+ specify 'a different string' do
56
+ expect('χρημάτων ἄελπτον οὐδέν ἐστιν οὐδ᾽ ἀπώμιον οὐδὲ θαυμάσιον').not_to match_ignoring_whitespace expected
57
+ end
58
+ specify 'a string missing a space' do
59
+ expect("πόλλ΄ οἶδ΄ ἀλώπηξ,ἀλλ΄ ἐχῖνος ἓν μέγα.").not_to match_ignoring_whitespace expected
60
+ end
61
+ specify 'expecting nil' do
62
+ expect('anything').not_to match_ignoring_whitespace(nil)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'rspec/match_ignoring_whitespace'
8
+
9
+ RSpec.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-match_ignoring_whitespace
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul A. Jungwirth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: RSpec matcher to compare strings ignoring whitespace
84
+ email:
85
+ - pj@illuminatedcomputing.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - ".yardopts"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/rspec/match_ignoring_whitespace.rb
100
+ - lib/rspec/match_ignoring_whitespace/version.rb
101
+ - rspec-match_ignoring_whitespace.gemspec
102
+ - spec/match_ignoring_whitespace_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/pjungwir/rspec-match_ignoring_whitespace
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: RSpec matcher to compare strings ignoring whitespace
128
+ test_files: []