rspec-uuid 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/uuid/version.rb +5 -0
- data/lib/rspec/uuid.rb +45 -0
- data/lib/rspec-uuid.rb +1 -38
- data/spec/matchers_spec.rb +26 -8
- metadata +5 -4
- data/lib/rspec-uuid/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a071e18425a466c1ad901fc015b3f683467d4b77ba7d1a151e57d0bf28b264
|
4
|
+
data.tar.gz: ee5776d8c999625c67a543bd3ecf40097a0983d9653fbc034505f0542137b51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c05681f2b05f9c78225f658b99f2fe96032660614cf32611cf1f5596e9d8869346a36d2762e53e0b41846e717ba1d6b0c5457779fc51058fc95f1c1fa8c50f57
|
7
|
+
data.tar.gz: 26cc496001d14ecb9829b21f1525f20e80ea7a139cfe24386700283946f9716269bb4bfefb86658059f09c59469581a8d3c08c1c4565efde0e897fcf515f355d
|
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
|
+
match do |actual|
|
5
|
+
raise ArgumentError if @version && version
|
6
|
+
|
7
|
+
return false unless actual.is_a?(String)
|
8
|
+
|
9
|
+
# https://www.uuidtools.com/what-is-uuid
|
10
|
+
matches = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/
|
11
|
+
return false unless matches
|
12
|
+
|
13
|
+
version ||= @version
|
14
|
+
if version
|
15
|
+
# 1st nibble of 3rd section
|
16
|
+
@actual_version = matches[1].to_i(16) >> 12
|
17
|
+
|
18
|
+
version == @actual_version
|
19
|
+
else
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
chain :of_version do |version|
|
25
|
+
@version = version
|
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/spec/matchers_spec.rb
CHANGED
@@ -49,22 +49,40 @@ describe "be_a_uuid" do
|
|
49
49
|
expect(uuid_v3).to be_a_uuid(version: 4)
|
50
50
|
}.to fail_including("expected a UUID v4, found a UUID v3")
|
51
51
|
end
|
52
|
+
|
53
|
+
describe ".of_version" do
|
54
|
+
it { expect(uuid_v3).to be_a_uuid.of_version(3) }
|
55
|
+
|
56
|
+
it { expect(uuid_v4).to be_a_uuid.of_version(4) }
|
57
|
+
it { expect(uuid_v4).not_to be_a_uuid.of_version(3) }
|
58
|
+
|
59
|
+
it "requires a version argument" do
|
60
|
+
expect {
|
61
|
+
expect(uuid_v4).to be_a_uuid.of_version
|
62
|
+
}.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "can not be used simultaneously with kwarg version" do
|
66
|
+
expect {
|
67
|
+
expect(uuid_v4).to be_a_uuid(version: 4).of_version(4)
|
68
|
+
}.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
end
|
52
71
|
end
|
53
72
|
|
54
73
|
it "is composable" do
|
55
74
|
data = {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
uuid_v5: Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, "123"),
|
60
|
-
},
|
61
|
-
foo: nil,
|
75
|
+
abc: { a: 1 },
|
76
|
+
uuid: SecureRandom.uuid,
|
77
|
+
uuid_v5: Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, "123"),
|
62
78
|
}
|
63
79
|
|
64
|
-
expect(data).to include(
|
80
|
+
expect(data).to include(uuid: a_uuid)
|
81
|
+
|
82
|
+
expect(data).to match(
|
65
83
|
abc: a_hash_including(:a),
|
66
84
|
uuid: a_uuid,
|
67
85
|
uuid_v5: a_uuid(version: 5),
|
68
|
-
|
86
|
+
)
|
69
87
|
end
|
70
88
|
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.5.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: 2022-
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -115,7 +115,8 @@ extensions: []
|
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
117
|
- lib/rspec-uuid.rb
|
118
|
-
- lib/rspec
|
118
|
+
- lib/rspec/uuid.rb
|
119
|
+
- lib/rspec/uuid/version.rb
|
119
120
|
- spec/matchers_spec.rb
|
120
121
|
homepage: https://github.com/dpep/rspec-uuid
|
121
122
|
licenses:
|
@@ -139,6 +140,6 @@ requirements: []
|
|
139
140
|
rubygems_version: 3.1.6
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
|
-
summary:
|
143
|
+
summary: Gem::Specification::RSpec::UUID
|
143
144
|
test_files:
|
144
145
|
- spec/matchers_spec.rb
|
data/lib/rspec-uuid/version.rb
DELETED