ezcater_matchers 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/ezcater_matchers.gemspec +53 -0
- data/lib/ezcater_matchers.rb +5 -0
- data/lib/ezcater_matchers/have_been_destroyed.rb +7 -0
- data/lib/ezcater_matchers/match_db_timestamp.rb +20 -0
- data/lib/ezcater_matchers/match_models.rb +40 -0
- data/lib/ezcater_matchers/match_ordered_array.rb +15 -0
- data/lib/ezcater_matchers/mismatched_collection_failure.rb +45 -0
- data/lib/ezcater_matchers/version.rb +5 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c967cc270d0724087f02c6d1792359836c90e0dcedc2812a2c79623622a4ef63
|
4
|
+
data.tar.gz: e72c033b5c79ec064d06cec912d402802d059cf55c1cbbd34c3a97af368cd4e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5689ef239af6e382e4f2698c1c8da6ed8806088f3b26c960efc366cd54e4985ed23af7809d5ed9fbb8f716838ac79c7f9f4ca1c839d023b9cb3ef059b4f90c04
|
7
|
+
data.tar.gz: bb77f08cc8083dd53f97019cd4bda09f325b87768d50619e005906c10a910976ddda433387bdaa2f1bb8fc79d82f4f36e8611c8dbb614effd5c40ddcb3ef11ba
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# ezcater_matchers
|
2
|
+
|
3
|
+
## v0.5.0
|
4
|
+
- Open source release
|
5
|
+
|
6
|
+
## v0.4.0
|
7
|
+
- Add `match_models` matcher
|
8
|
+
|
9
|
+
## v0.3.0
|
10
|
+
- Add `match_db_timestamp` matcher
|
11
|
+
|
12
|
+
## v0.2.0
|
13
|
+
- Add `have_been_destroyed` matcher
|
14
|
+
|
15
|
+
## v0.1.0
|
16
|
+
- Initial version
|
17
|
+
- Add `match_ordered_array` matcher
|
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# override the :github shortcut to be secure by using HTTPS
|
6
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
|
7
|
+
|
8
|
+
# Specify your gem's dependencies in ezcater_matchers.gemspec
|
9
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 ezCater, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# ezcater_matchers
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/ezcater/ezcater_matchers.svg?style=svg)](https://circleci.com/gh/ezcater/ezcater_matchers)
|
4
|
+
|
5
|
+
This gem contains shared RSpec matchers.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
group :test do
|
13
|
+
gem "ezcater_matchers"
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install ezcater_matchers
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Matchers
|
28
|
+
|
29
|
+
The matchers included in this gem are:
|
30
|
+
|
31
|
+
* **have_been_destroyed**: To check that a model has (or has not) been destroyed.
|
32
|
+
* **match_db_timestamp**: Compares two timestamps for equality with DB precision (drops nanoseconds).
|
33
|
+
* **match_models**: Compare an enumerable to an expected list of ActiveRecord model objects (by id/type).
|
34
|
+
* **match_ordered_array**: To check that an array has exactly the expected, ordered elements.
|
35
|
+
|
36
|
+
### Examples
|
37
|
+
|
38
|
+
#### match_models
|
39
|
+
|
40
|
+
You can use `match_models` to simplify comparing enumerables/ActiveRecord relations to a single expected example:
|
41
|
+
```
|
42
|
+
my_model = build(:your_model)
|
43
|
+
|
44
|
+
expect(YourModel.scope).to match_models(my_model)
|
45
|
+
```
|
46
|
+
|
47
|
+
You can use `match_models` to compare complex, heterogeneous result lists:
|
48
|
+
|
49
|
+
```
|
50
|
+
caterer = create(:caterer, name: "matches")
|
51
|
+
brand = create(:caterer, name: "matches")
|
52
|
+
|
53
|
+
expect(FullTextSearch.call("matches")).to match_models(caterer, brand)
|
54
|
+
```
|
55
|
+
|
56
|
+
You can also chain the `match_models` matcher to respect/ignore enumerable ordering, which is helpful in combatting flaky tests where order is not 100% deterministic:
|
57
|
+
```
|
58
|
+
caterer = create(:caterer, name: "matches")
|
59
|
+
brand = create(:caterer, name: "matches")
|
60
|
+
|
61
|
+
expect(RandomOrderedSearch.call("matches")).to match_models(caterer, brand).unordered
|
62
|
+
```
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
67
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
68
|
+
interactive prompt that will allow you to experiment.
|
69
|
+
|
70
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
71
|
+
|
72
|
+
To release a new version, update the version number in `version.rb`, and then
|
73
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
74
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at
|
79
|
+
https://github.com/ezcater/ezcater_matchers.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "ezcater_matchers/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "ezcater_matchers"
|
9
|
+
spec.version = EzcaterMatchers::VERSION
|
10
|
+
spec.authors = ["ezCater, Inc"]
|
11
|
+
spec.email = ["engineering@ezcater.com"]
|
12
|
+
|
13
|
+
spec.summary = "shared matchers"
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = "https://github.com/ezcater/ezcater_matchers"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Set "allowed_push_post" to control where this gem can be published.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
excluded_files = %w(.circleci/config.yml
|
26
|
+
.github/PULL_REQUEST_TEMPLATE.md
|
27
|
+
.gitignore
|
28
|
+
.rspec
|
29
|
+
.rubocop.yml
|
30
|
+
.ruby-gemset
|
31
|
+
.ruby-version
|
32
|
+
.travis.yml
|
33
|
+
bin/console
|
34
|
+
bin/setup
|
35
|
+
Rakefile)
|
36
|
+
|
37
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
38
|
+
f.match(/^(test|spec|features)\//)
|
39
|
+
end - excluded_files
|
40
|
+
spec.bindir = "bin"
|
41
|
+
spec.executables = []
|
42
|
+
spec.require_paths = ["lib"]
|
43
|
+
|
44
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
45
|
+
spec.add_development_dependency "ezcater_gem", ">= 0.2.0"
|
46
|
+
spec.add_development_dependency "ezcater_rubocop", "0.57.2"
|
47
|
+
spec.add_development_dependency "overcommit"
|
48
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
49
|
+
spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
|
50
|
+
spec.add_development_dependency "simplecov"
|
51
|
+
|
52
|
+
spec.add_runtime_dependency "rspec", "~> 3.4"
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Compare one or more ActiveRecord database Timestamp values, with db precision (drops nanoseconds)
|
4
|
+
RSpec::Matchers.define :match_db_timestamp do |expected|
|
5
|
+
match do |actual|
|
6
|
+
expect(db_precision(actual)).to eq(db_precision(expected))
|
7
|
+
end
|
8
|
+
|
9
|
+
failure_message do |actual|
|
10
|
+
"expected #{debug_timestamp(db_precision(actual))} to match #{debug_timestamp(db_precision(expected))}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def db_precision(timestamp)
|
14
|
+
timestamp.change(nsec: 0)
|
15
|
+
end
|
16
|
+
|
17
|
+
def debug_timestamp(timestamp)
|
18
|
+
"#{timestamp} (#{timestamp.to_f})"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Compare one or more ActiveRecord models to an enumerable of actual results
|
4
|
+
# Error messages display friendly output of `ModelClass-id` tuples for debugging
|
5
|
+
RSpec::Matchers.define :match_models do |*expected| # rubocop:disable Metrics/BlockLength
|
6
|
+
@comparator = :equality
|
7
|
+
|
8
|
+
match do |actual|
|
9
|
+
case @comparator
|
10
|
+
when :set
|
11
|
+
expect(actual_models(actual).to_set).to eq(expected_models(expected).to_set)
|
12
|
+
else
|
13
|
+
expect(actual_models(actual)).to eq(expected_models(expected))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message do |actual|
|
18
|
+
"expected #{expected_models(expected).inspect} but got #{actual_models(actual)}"
|
19
|
+
end
|
20
|
+
|
21
|
+
chain :ordered do
|
22
|
+
@comparator = :equality
|
23
|
+
end
|
24
|
+
|
25
|
+
chain :unordered do
|
26
|
+
@comparator = :set
|
27
|
+
end
|
28
|
+
|
29
|
+
def actual_models(actual_array)
|
30
|
+
actual_array.to_a.map { |obj| object_name(obj) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def expected_models(expected_array)
|
34
|
+
expected_array.map { |obj| object_name(obj) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def object_name(obj)
|
38
|
+
"#{obj.class.name}-#{obj.id}"
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ezcater_matchers/mismatched_collection_failure"
|
4
|
+
|
5
|
+
RSpec::Matchers.define :match_ordered_array do |expected|
|
6
|
+
match do |actual|
|
7
|
+
actual == expected
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message do |actual|
|
11
|
+
EzcaterMatchers::MismatchedCollectionFailure.
|
12
|
+
new(actual: actual, expected: expected).
|
13
|
+
message
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EzcaterMatchers
|
4
|
+
class MismatchedCollectionFailure
|
5
|
+
attr_reader :message
|
6
|
+
|
7
|
+
def initialize(actual:, expected:)
|
8
|
+
@actual = actual
|
9
|
+
@expected = expected
|
10
|
+
@message = message_array.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :actual, :expected
|
16
|
+
|
17
|
+
def message_array
|
18
|
+
[].tap do |messages|
|
19
|
+
messages.push(extra_elements_message) if extra_elements.any?
|
20
|
+
messages.push(missing_elements_message) if missing_elements.any?
|
21
|
+
messages.push(unexpected_order_message) if missing_elements.empty? && extra_elements.empty?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def extra_elements_message
|
26
|
+
"the extra elements were: #{extra_elements}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def extra_elements
|
30
|
+
@_extra_elements ||= actual - expected
|
31
|
+
end
|
32
|
+
|
33
|
+
def missing_elements_message
|
34
|
+
"the missing elements were: #{missing_elements}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def missing_elements
|
38
|
+
@_missing_elements ||= expected - actual
|
39
|
+
end
|
40
|
+
|
41
|
+
def unexpected_order_message
|
42
|
+
"the elements are not in the expected order"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ezcater_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ezCater, Inc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ezcater_gem
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.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.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ezcater_rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.57.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.57.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: overcommit
|
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: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.2.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.2.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.4'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.4'
|
125
|
+
description: shared matchers
|
126
|
+
email:
|
127
|
+
- engineering@ezcater.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- CHANGELOG.md
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- ezcater_matchers.gemspec
|
137
|
+
- lib/ezcater_matchers.rb
|
138
|
+
- lib/ezcater_matchers/have_been_destroyed.rb
|
139
|
+
- lib/ezcater_matchers/match_db_timestamp.rb
|
140
|
+
- lib/ezcater_matchers/match_models.rb
|
141
|
+
- lib/ezcater_matchers/match_ordered_array.rb
|
142
|
+
- lib/ezcater_matchers/mismatched_collection_failure.rb
|
143
|
+
- lib/ezcater_matchers/version.rb
|
144
|
+
homepage: https://github.com/ezcater/ezcater_matchers
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata:
|
148
|
+
allowed_push_host: https://rubygems.org
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.7.6
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: shared matchers
|
169
|
+
test_files: []
|