rspec-uuid 0.3.0 → 0.4.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: caa7afca895de94cad4ceea528171b93482976b45b6a59e96103d14fcf42c2e6
4
- data.tar.gz: fd24385339537457902c4a6750e0847f4c1face45d7bf9d47ab26a2a194c6c38
3
+ metadata.gz: 9734bb31d88892de3d5c141afbcdbd444b942f327863c4e87be0198b0cf0d3e9
4
+ data.tar.gz: 7672b8b47603a9f895fb4586af1141edd7b0693c492991a5fecc1847f7f42348
5
5
  SHA512:
6
- metadata.gz: c5f3f2e09137b49762079e80abd5d0f4962b25dd783db6c8cd3bf2750ad976fc962341f4fdec938d346521696a5f1f4ab4f15e0f35993470d43d570f3b4275cd
7
- data.tar.gz: 5e8327d444a20dc4c1e393ca642b8d9cdb35059a335bfc3ab9f50937a9804df5f13b392bed25d0be8ab3168705e4ac3077bf1fafbbb3877f9eca2a39e916073f
6
+ metadata.gz: c59ae103abe71f91cb4902c2a98d33084cc5cfa5726c0c723fdb19267f85ff29f1f76ffc366d598743c740f49635b75490747f8a53a455b3bef84ffb14400262
7
+ data.tar.gz: c5cefea9b062dd117b02491684cc221b52651c56801975458519c222dac9152a8bfcbbb15dbe8d475dcdf2e94b304974cab9d8e47696f032be3cbb17828256f2
@@ -1,3 +1,3 @@
1
1
  module RSpecUUID
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/rspec-uuid.rb CHANGED
@@ -1,8 +1,38 @@
1
- require "rspec/core"
2
1
  require "rspec/expectations"
3
- require "rspec-uuid/matchers"
4
- require "rspec-uuid/version"
5
2
 
6
- RSpec.configure do |config|
7
- config.include(RSpecUUID::Matchers)
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
8
36
  end
37
+
38
+ RSpec::Matchers.alias_matcher :a_uuid, :be_a_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
 
@@ -50,4 +50,21 @@ describe RSpecUUID::Matchers do
50
50
  }.to fail_including("expected a UUID v4, found a UUID v3")
51
51
  end
52
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
53
70
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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-19 00:00:00.000000000 Z
11
+ date: 2022-05-24 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
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +115,6 @@ extensions: []
101
115
  extra_rdoc_files: []
102
116
  files:
103
117
  - lib/rspec-uuid.rb
104
- - lib/rspec-uuid/matchers.rb
105
118
  - lib/rspec-uuid/version.rb
106
119
  - spec/matchers_spec.rb
107
120
  homepage: https://github.com/dpep/rspec-uuid
@@ -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