rspec-uuid 0.1.0 → 0.3.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/matchers.rb +27 -8
- data/lib/rspec-uuid/version.rb +1 -1
- data/spec/matchers_spec.rb +31 -10
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa7afca895de94cad4ceea528171b93482976b45b6a59e96103d14fcf42c2e6
|
4
|
+
data.tar.gz: fd24385339537457902c4a6750e0847f4c1face45d7bf9d47ab26a2a194c6c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f3f2e09137b49762079e80abd5d0f4962b25dd783db6c8cd3bf2750ad976fc962341f4fdec938d346521696a5f1f4ab4f15e0f35993470d43d570f3b4275cd
|
7
|
+
data.tar.gz: 5e8327d444a20dc4c1e393ca642b8d9cdb35059a335bfc3ab9f50937a9804df5f13b392bed25d0be8ab3168705e4ac3077bf1fafbbb3877f9eca2a39e916073f
|
data/lib/rspec-uuid/matchers.rb
CHANGED
@@ -1,28 +1,47 @@
|
|
1
1
|
module RSpecUUID
|
2
2
|
module Matchers
|
3
3
|
class UUIDMatcher
|
4
|
-
def
|
5
|
-
|
4
|
+
def initialize(version: nil)
|
5
|
+
@version = version
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual)
|
9
|
+
return false unless actual.is_a?(String)
|
6
10
|
|
7
11
|
# https://www.uuidtools.com/what-is-uuid
|
8
|
-
|
12
|
+
match = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/
|
13
|
+
|
14
|
+
return false unless match
|
15
|
+
|
16
|
+
if @version
|
17
|
+
# 1st nibble of 3rd section
|
18
|
+
@actual_version = match[1].to_i(16) >> 12
|
19
|
+
|
20
|
+
@version == @actual_version
|
21
|
+
else
|
22
|
+
true
|
23
|
+
end
|
9
24
|
end
|
10
25
|
|
11
26
|
def description
|
12
|
-
"
|
27
|
+
@version ? "a UUID v#{@version}" : "a UUID"
|
13
28
|
end
|
14
29
|
|
15
30
|
def failure_message
|
16
|
-
|
31
|
+
if @actual_version
|
32
|
+
"expected #{description}, found a UUID v#{@actual_version}"
|
33
|
+
else
|
34
|
+
"expected #{description}"
|
35
|
+
end
|
17
36
|
end
|
18
37
|
|
19
38
|
def failure_message_when_negated
|
20
|
-
"did not expect
|
39
|
+
"did not expect #{description}"
|
21
40
|
end
|
22
41
|
end
|
23
42
|
|
24
|
-
def be_a_uuid
|
25
|
-
UUIDMatcher.new
|
43
|
+
def be_a_uuid(...)
|
44
|
+
UUIDMatcher.new(...)
|
26
45
|
end
|
27
46
|
end
|
28
47
|
end
|
data/lib/rspec-uuid/version.rb
CHANGED
data/spec/matchers_spec.rb
CHANGED
@@ -5,8 +5,9 @@ describe RSpecUUID::Matchers do
|
|
5
5
|
specify { expect(uuid).to be_a_uuid }
|
6
6
|
end
|
7
7
|
|
8
|
-
context "with
|
8
|
+
context "with generated UUIDs" do
|
9
9
|
specify do
|
10
|
+
100.times { expect(SecureRandom.uuid).to be_a_uuid }
|
10
11
|
100.times { expect(Faker::Internet.uuid).to be_a_uuid }
|
11
12
|
end
|
12
13
|
end
|
@@ -16,17 +17,37 @@ describe RSpecUUID::Matchers do
|
|
16
17
|
specify { expect(:xyz).not_to be_a_uuid }
|
17
18
|
specify { expect(123).not_to be_a_uuid }
|
18
19
|
specify { expect(nil).not_to be_a_uuid }
|
19
|
-
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
32
|
end
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
52
|
end
|
32
53
|
end
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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-05-
|
11
|
+
date: 2022-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -25,7 +39,7 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: byebug
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: codecov
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: faker
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|