rspec-uuid 0.2.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86976570717b28f357f79552d53198d57041efc2ac7e96706d0c8415bdd85782
4
- data.tar.gz: c561df77eb3e2867b3ff3818ce2c865c8ba1d03354814116c844faea74ca58c0
3
+ metadata.gz: 01a071e18425a466c1ad901fc015b3f683467d4b77ba7d1a151e57d0bf28b264
4
+ data.tar.gz: ee5776d8c999625c67a543bd3ecf40097a0983d9653fbc034505f0542137b51f
5
5
  SHA512:
6
- metadata.gz: 0616ab1c8402b8f4c0977778a38a0a59cb5a511173d30433d920a2aa521a651272046fb135ef478cfa231c7526c904382bace79b95042efc7bf912d1a38c5f3e
7
- data.tar.gz: 2e453940a2a49faa22f2b3933e300b4b986f16080934aca2d0c0acaf39cab022221d9a7ba22609c8abb90c3b5cdb384763b1331bffc52f76832326407d5536c4
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,8 +1 @@
1
- require "rspec/core"
2
- require "rspec/expectations"
3
- require "rspec-uuid/matchers"
4
- require "rspec-uuid/version"
5
-
6
- RSpec.configure do |config|
7
- config.include(RSpecUUID::Matchers)
8
- end
1
+ require "rspec/uuid"
@@ -1,4 +1,4 @@
1
- describe RSpecUUID::Matchers do
1
+ describe "be_a_uuid" do
2
2
  context "with a valid UUID" do
3
3
  let(:uuid) { "992c94bd-5870-4e02-ad2d-a9435f7fffe6" }
4
4
 
@@ -37,17 +37,52 @@ describe RSpecUUID::Matchers do
37
37
  let(:uuid_v4) { SecureRandom.uuid }
38
38
  let(:uuid_v5) { Digest::UUID.uuid_v5(namespace, "123") }
39
39
 
40
- specify { expect(uuid_v3).to be_a_uuid(3) }
41
- specify { expect(uuid_v3).not_to be_a_uuid(4) }
42
- specify { expect(uuid_v3).not_to be_a_uuid(5) }
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
43
 
44
- specify { expect(uuid_v4).to be_a_uuid(4) }
45
- specify { expect(uuid_v5).to be_a_uuid(5) }
44
+ specify { expect(uuid_v4).to be_a_uuid(version: 4) }
45
+ specify { expect(uuid_v5).to be_a_uuid(version: 5) }
46
46
 
47
47
  it "fails with a useful message" do
48
48
  expect {
49
- expect(uuid_v3).to be_a_uuid(4)
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
71
+ end
72
+
73
+ it "is composable" do
74
+ data = {
75
+ abc: { a: 1 },
76
+ uuid: SecureRandom.uuid,
77
+ uuid_v5: Digest::UUID.uuid_v5(Digest::UUID::OID_NAMESPACE, "123"),
78
+ }
79
+
80
+ expect(data).to include(uuid: a_uuid)
81
+
82
+ expect(data).to match(
83
+ abc: a_hash_including(:a),
84
+ uuid: a_uuid,
85
+ uuid_v5: a_uuid(version: 5),
86
+ )
52
87
  end
53
88
  end
metadata CHANGED
@@ -1,37 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
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-17 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
- name: rspec
14
+ name: rspec-expectations
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec-expectations
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: byebug
56
+ name: codecov
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: codecov
70
+ name: faker
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: faker
84
+ name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -115,8 +115,8 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - lib/rspec-uuid.rb
118
- - lib/rspec-uuid/matchers.rb
119
- - lib/rspec-uuid/version.rb
118
+ - lib/rspec/uuid.rb
119
+ - lib/rspec/uuid/version.rb
120
120
  - spec/matchers_spec.rb
121
121
  homepage: https://github.com/dpep/rspec-uuid
122
122
  licenses:
@@ -140,6 +140,6 @@ requirements: []
140
140
  rubygems_version: 3.1.6
141
141
  signing_key:
142
142
  specification_version: 4
143
- summary: RSpecUUID
143
+ summary: Gem::Specification::RSpec::UUID
144
144
  test_files:
145
145
  - spec/matchers_spec.rb
@@ -1,47 +0,0 @@
1
- module RSpecUUID
2
- module Matchers
3
- class UUIDMatcher
4
- def initialize(version = nil)
5
- @version = version
6
- end
7
-
8
- def matches?(actual)
9
- return false unless actual.is_a?(String)
10
-
11
- # https://www.uuidtools.com/what-is-uuid
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
24
- end
25
-
26
- def description
27
- @version ? "a UUID v#{@version}" : "a UUID"
28
- end
29
-
30
- def failure_message
31
- if @actual_version
32
- "expected #{description}, found a UUID v#{@actual_version}"
33
- else
34
- "expected #{description}"
35
- end
36
- end
37
-
38
- def failure_message_when_negated
39
- "did not expect #{description}"
40
- end
41
- end
42
-
43
- def be_a_uuid(...)
44
- UUIDMatcher.new(...)
45
- end
46
- end
47
- end
@@ -1,3 +0,0 @@
1
- module RSpecUUID
2
- VERSION = "0.2.1"
3
- end