rspec-uuid 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9734bb31d88892de3d5c141afbcdbd444b942f327863c4e87be0198b0cf0d3e9
4
- data.tar.gz: 7672b8b47603a9f895fb4586af1141edd7b0693c492991a5fecc1847f7f42348
3
+ metadata.gz: 01a071e18425a466c1ad901fc015b3f683467d4b77ba7d1a151e57d0bf28b264
4
+ data.tar.gz: ee5776d8c999625c67a543bd3ecf40097a0983d9653fbc034505f0542137b51f
5
5
  SHA512:
6
- metadata.gz: c59ae103abe71f91cb4902c2a98d33084cc5cfa5726c0c723fdb19267f85ff29f1f76ffc366d598743c740f49635b75490747f8a53a455b3bef84ffb14400262
7
- data.tar.gz: c5cefea9b062dd117b02491684cc221b52651c56801975458519c222dac9152a8bfcbbb15dbe8d475dcdf2e94b304974cab9d8e47696f032be3cbb17828256f2
6
+ metadata.gz: c05681f2b05f9c78225f658b99f2fe96032660614cf32611cf1f5596e9d8869346a36d2762e53e0b41846e717ba1d6b0c5457779fc51058fc95f1c1fa8c50f57
7
+ data.tar.gz: 26cc496001d14ecb9829b21f1525f20e80ea7a139cfe24386700283946f9716269bb4bfefb86658059f09c59469581a8d3c08c1c4565efde0e897fcf515f355d
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module UUID
3
+ VERSION = "0.5.0"
4
+ end
5
+ end
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/expectations"
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"
@@ -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
- 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,
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(res: {
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.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-05-24 00:00:00.000000000 Z
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-uuid/version.rb
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: RSpecUUID
143
+ summary: Gem::Specification::RSpec::UUID
143
144
  test_files:
144
145
  - spec/matchers_spec.rb
@@ -1,3 +0,0 @@
1
- module RSpecUUID
2
- VERSION = "0.4.0"
3
- end