rspec-uuid 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/lib/rspec/uuid/version.rb +5 -0
- data/lib/rspec/uuid.rb +45 -0
- data/lib/rspec-uuid.rb +1 -38
- data/rspec-uuid.gemspec +25 -0
- metadata +18 -13
- data/lib/rspec-uuid/version.rb +0 -3
- data/spec/matchers_spec.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 182a16e53a65c328fd32f92aef6b5d9bb5d52e92cf08cc67f5799eaaea72f13d
|
4
|
+
data.tar.gz: 7cd4ffa9c8e7a7427b32ba1d48ce59a39c81728c4fe54563c05cb604596225b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b58fa677009b056653611cf8950e651e89db53229e06fe4d8673a0cfd4f65775b8e26f3d02b0ba97821eed76b255423130e608d3fea00fcc2330058481e8894
|
7
|
+
data.tar.gz: fab7586801890f4eef8268690c6568c53afb6fb4a62f2ee2910b1860ad3dfc85917d6bdb2c53a9fc7c94b31432e3e1190dd3c53a119dbb3d61ecfa954923779e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
### v0.6.0 (2024-04-08)
|
2
|
+
- drop ruby 2.7
|
3
|
+
- dependabot upgrades
|
4
|
+
- uuid_v7
|
5
|
+
- gemspec fixup
|
6
|
+
- codecov upgrade (#1)
|
7
|
+
- add lockfile and dependabot
|
8
|
+
|
9
|
+
### v0.5.0 (2022-06-08)
|
10
|
+
- move to "rspec/uuid"
|
11
|
+
- .of_version chain
|
12
|
+
- Update README.md
|
13
|
+
- simplify composition spec
|
14
|
+
|
15
|
+
### v0.4.0 (2022-05-23)
|
16
|
+
- rspec 3
|
17
|
+
- Update README.md
|
18
|
+
|
19
|
+
### v0.3.0 (2022-05-19)
|
20
|
+
- version kwarg
|
21
|
+
|
22
|
+
### v0.2.1 (2022-05-16)
|
23
|
+
- requirements
|
24
|
+
- faker coverage
|
25
|
+
- Update README.md
|
26
|
+
|
27
|
+
### v0.2.0 (2022-05-13)
|
28
|
+
- uuid version support
|
29
|
+
- Update README.md
|
30
|
+
|
31
|
+
### v0.1.0 (2022-05-12)
|
32
|
+
- voila
|
33
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-uuid (0.6.0)
|
5
|
+
rspec-expectations (>= 3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.1.3.2)
|
11
|
+
base64
|
12
|
+
bigdecimal
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
connection_pool (>= 2.2.5)
|
15
|
+
drb
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
mutex_m
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
base64 (0.2.0)
|
21
|
+
bigdecimal (3.1.6)
|
22
|
+
byebug (11.1.3)
|
23
|
+
concurrent-ruby (1.2.3)
|
24
|
+
connection_pool (2.4.1)
|
25
|
+
diff-lcs (1.5.1)
|
26
|
+
docile (1.4.0)
|
27
|
+
drb (2.2.0)
|
28
|
+
ruby2_keywords
|
29
|
+
faker (3.3.0)
|
30
|
+
i18n (>= 1.8.11, < 2)
|
31
|
+
i18n (1.14.4)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
minitest (5.22.2)
|
34
|
+
mutex_m (0.2.0)
|
35
|
+
rspec (3.13.0)
|
36
|
+
rspec-core (~> 3.13.0)
|
37
|
+
rspec-expectations (~> 3.13.0)
|
38
|
+
rspec-mocks (~> 3.13.0)
|
39
|
+
rspec-core (3.13.0)
|
40
|
+
rspec-support (~> 3.13.0)
|
41
|
+
rspec-expectations (3.13.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.13.0)
|
44
|
+
rspec-mocks (3.13.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.13.0)
|
47
|
+
rspec-support (3.13.0)
|
48
|
+
ruby2_keywords (0.0.5)
|
49
|
+
simplecov (0.22.0)
|
50
|
+
docile (~> 1.1)
|
51
|
+
simplecov-html (~> 0.11)
|
52
|
+
simplecov_json_formatter (~> 0.1)
|
53
|
+
simplecov-html (0.12.3)
|
54
|
+
simplecov_json_formatter (0.1.4)
|
55
|
+
tzinfo (2.0.6)
|
56
|
+
concurrent-ruby (~> 1.0)
|
57
|
+
uuid7 (0.2.0)
|
58
|
+
zeitwerk (~> 2.4)
|
59
|
+
zeitwerk (2.6.12)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
activesupport
|
66
|
+
byebug
|
67
|
+
faker
|
68
|
+
rspec
|
69
|
+
rspec-uuid!
|
70
|
+
simplecov
|
71
|
+
uuid7
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.4.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Daniel Pepper
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
rspec-uuid
|
2
|
+
======
|
3
|
+
![Gem](https://img.shields.io/gem/dt/rspec-uuid?style=plastic)
|
4
|
+
[![codecov](https://codecov.io/gh/dpep/rspec-uuid/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/rspec-uuid)
|
5
|
+
|
6
|
+
|
7
|
+
An RSpec matcher for UUIDs.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "rspec/uuid"
|
11
|
+
|
12
|
+
|
13
|
+
it { is_expected.to be_a_uuid }
|
14
|
+
|
15
|
+
# check the version
|
16
|
+
it { is_expected.to be_a_uuid(version: 4) }
|
17
|
+
it { is_expected.to be_a_uuid.of_version(4) }
|
18
|
+
|
19
|
+
# compose with other matchers
|
20
|
+
it { expect(data).to include(uuid: a_uuid) }
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
----
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Yes please :)
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
1. Create your feature branch (`git checkout -b my-feature`)
|
31
|
+
1. Ensure the tests pass (`bundle exec rspec`)
|
32
|
+
1. Commit your changes (`git commit -am 'awesome new feature'`)
|
33
|
+
1. Push your branch (`git push origin my-feature`)
|
34
|
+
1. Create a Pull Request
|
data/lib/rspec/uuid.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
|
3
|
+
RSpec::Matchers.define :be_a_uuid do |version: nil|
|
4
|
+
chain :of_version do |version|
|
5
|
+
@version = version
|
6
|
+
end
|
7
|
+
|
8
|
+
match do |actual|
|
9
|
+
raise ArgumentError if @version && version
|
10
|
+
|
11
|
+
return false unless actual.is_a?(String)
|
12
|
+
|
13
|
+
# https://www.uuidtools.com/what-is-uuid
|
14
|
+
matches = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/
|
15
|
+
return false unless matches
|
16
|
+
|
17
|
+
version ||= @version
|
18
|
+
if version
|
19
|
+
# 1st nibble of 3rd section
|
20
|
+
@actual_version = matches[1].to_i(16) >> 12
|
21
|
+
|
22
|
+
version == @actual_version
|
23
|
+
else
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
description do
|
29
|
+
version ? "a UUID v#{version}" : "a UUID"
|
30
|
+
end
|
31
|
+
|
32
|
+
failure_message do
|
33
|
+
if @actual_version
|
34
|
+
"expected #{description}, found a UUID v#{@actual_version}"
|
35
|
+
else
|
36
|
+
"expected #{description}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
failure_message_when_negated do
|
41
|
+
"did not expect #{description}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec::Matchers.alias_matcher :a_uuid, :be_a_uuid
|
data/lib/rspec-uuid.rb
CHANGED
@@ -1,38 +1 @@
|
|
1
|
-
require "rspec/
|
2
|
-
|
3
|
-
RSpec::Matchers.define :be_a_uuid do |version: nil|
|
4
|
-
match do |actual|
|
5
|
-
return false unless actual.is_a?(String)
|
6
|
-
|
7
|
-
# https://www.uuidtools.com/what-is-uuid
|
8
|
-
matches = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/
|
9
|
-
return false unless matches
|
10
|
-
|
11
|
-
if version
|
12
|
-
# 1st nibble of 3rd section
|
13
|
-
@actual_version = matches[1].to_i(16) >> 12
|
14
|
-
|
15
|
-
version == @actual_version
|
16
|
-
else
|
17
|
-
true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
description do
|
22
|
-
version ? "a UUID v#{version}" : "a UUID"
|
23
|
-
end
|
24
|
-
|
25
|
-
failure_message do
|
26
|
-
if @actual_version
|
27
|
-
"expected #{description}, found a UUID v#{@actual_version}"
|
28
|
-
else
|
29
|
-
"expected #{description}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
failure_message_when_negated do
|
34
|
-
"did not expect #{description}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
RSpec::Matchers.alias_matcher :a_uuid, :be_a_uuid
|
1
|
+
require "rspec/uuid"
|
data/rspec-uuid.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "lib/rspec/uuid/version"
|
2
|
+
package = RSpec::UUID
|
3
|
+
package_name = "rspec-uuid"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.authors = ["Daniel Pepper"]
|
7
|
+
s.description = "RSpec UUID matcher"
|
8
|
+
s.files = `git ls-files * ':!:spec'`.split("\n")
|
9
|
+
s.homepage = "https://github.com/dpep/#{package_name}"
|
10
|
+
s.license = "MIT"
|
11
|
+
s.name = package_name
|
12
|
+
s.summary = package.to_s
|
13
|
+
s.version = package.const_get "VERSION"
|
14
|
+
|
15
|
+
s.required_ruby_version = ">= 3"
|
16
|
+
|
17
|
+
s.add_dependency "rspec-expectations", ">= 3"
|
18
|
+
|
19
|
+
s.add_development_dependency "activesupport"
|
20
|
+
s.add_development_dependency "byebug"
|
21
|
+
s.add_development_dependency "faker"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "simplecov"
|
24
|
+
s.add_development_dependency "uuid7"
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: faker
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: uuid7
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -114,9 +114,15 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
|
+
- CHANGELOG.md
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
117
122
|
- lib/rspec-uuid.rb
|
118
|
-
- lib/rspec
|
119
|
-
-
|
123
|
+
- lib/rspec/uuid.rb
|
124
|
+
- lib/rspec/uuid/version.rb
|
125
|
+
- rspec-uuid.gemspec
|
120
126
|
homepage: https://github.com/dpep/rspec-uuid
|
121
127
|
licenses:
|
122
128
|
- MIT
|
@@ -129,16 +135,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
135
|
requirements:
|
130
136
|
- - ">="
|
131
137
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
138
|
+
version: '3'
|
133
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
140
|
requirements:
|
135
141
|
- - ">="
|
136
142
|
- !ruby/object:Gem::Version
|
137
143
|
version: '0'
|
138
144
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.5.7
|
140
146
|
signing_key:
|
141
147
|
specification_version: 4
|
142
|
-
summary:
|
143
|
-
test_files:
|
144
|
-
- spec/matchers_spec.rb
|
148
|
+
summary: RSpec::UUID
|
149
|
+
test_files: []
|
data/lib/rspec-uuid/version.rb
DELETED
data/spec/matchers_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
describe "be_a_uuid" do
|
2
|
-
context "with a valid UUID" do
|
3
|
-
let(:uuid) { "992c94bd-5870-4e02-ad2d-a9435f7fffe6" }
|
4
|
-
|
5
|
-
specify { expect(uuid).to be_a_uuid }
|
6
|
-
end
|
7
|
-
|
8
|
-
context "with generated UUIDs" do
|
9
|
-
specify do
|
10
|
-
100.times { expect(SecureRandom.uuid).to be_a_uuid }
|
11
|
-
100.times { expect(Faker::Internet.uuid).to be_a_uuid }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "with invalid UUIDs" do
|
16
|
-
specify { expect("abc").not_to be_a_uuid }
|
17
|
-
specify { expect(:xyz).not_to be_a_uuid }
|
18
|
-
specify { expect(123).not_to be_a_uuid }
|
19
|
-
specify { expect(nil).not_to be_a_uuid }
|
20
|
-
|
21
|
-
it "fails with a useful message" do
|
22
|
-
expect {
|
23
|
-
expect(nil).to be_a_uuid
|
24
|
-
}.to fail_including("expected a UUID")
|
25
|
-
end
|
26
|
-
|
27
|
-
it "fails with a useful negation message" do
|
28
|
-
expect {
|
29
|
-
expect(SecureRandom.uuid).not_to be_a_uuid
|
30
|
-
}.to fail_including("did not expect a UUID")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with a UUID version" do
|
35
|
-
let(:namespace) { Digest::UUID::OID_NAMESPACE }
|
36
|
-
let(:uuid_v3) { Digest::UUID.uuid_v3(namespace, "123") }
|
37
|
-
let(:uuid_v4) { SecureRandom.uuid }
|
38
|
-
let(:uuid_v5) { Digest::UUID.uuid_v5(namespace, "123") }
|
39
|
-
|
40
|
-
specify { expect(uuid_v3).to be_a_uuid(version: 3) }
|
41
|
-
specify { expect(uuid_v3).not_to be_a_uuid(version: 4) }
|
42
|
-
specify { expect(uuid_v3).not_to be_a_uuid(version: 5) }
|
43
|
-
|
44
|
-
specify { expect(uuid_v4).to be_a_uuid(version: 4) }
|
45
|
-
specify { expect(uuid_v5).to be_a_uuid(version: 5) }
|
46
|
-
|
47
|
-
it "fails with a useful message" do
|
48
|
-
expect {
|
49
|
-
expect(uuid_v3).to be_a_uuid(version: 4)
|
50
|
-
}.to fail_including("expected a UUID v4, found a UUID v3")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "is composable" do
|
55
|
-
data = {
|
56
|
-
res: {
|
57
|
-
abc: { a: 1 },
|
58
|
-
uuid: SecureRandom.uuid,
|
59
|
-
uuid_v5: Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, "123"),
|
60
|
-
},
|
61
|
-
foo: nil,
|
62
|
-
}
|
63
|
-
|
64
|
-
expect(data).to include(res: {
|
65
|
-
abc: a_hash_including(:a),
|
66
|
-
uuid: a_uuid,
|
67
|
-
uuid_v5: a_uuid(version: 5),
|
68
|
-
})
|
69
|
-
end
|
70
|
-
end
|