Skip to content

Commit 73c1d52

Browse files
committed
move to "rspec/uuid"
1 parent d166656 commit 73c1d52

File tree

6 files changed

+55
-51
lines changed

6 files changed

+55
-51
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ rspec-uuid
77
An RSpec matcher for UUIDs.
88

99
```ruby
10-
require "rspec-uuid"
10+
require "rspec/uuid"
1111

1212

1313
it { is_expected.to be_a_uuid }
1414

1515
# check the version
1616
it { is_expected.to be_a_uuid(version: 4) }
17+
it { is_expected.to be_a_uuid.of_version(4) }
1718

1819
# compose with other matchers
1920
it { expect(data).to include(uuid: a_uuid) }

lib/rspec-uuid.rb

+1-45
Original file line numberDiff line numberDiff line change
@@ -1,45 +1 @@
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
1+
require "rspec/uuid"

lib/rspec-uuid/version.rb

-3
This file was deleted.

lib/rspec/uuid.rb

+45
Original file line numberDiff line numberDiff line change
@@ -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

lib/rspec/uuid/version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module RSpec
2+
module UUID
3+
VERSION = "0.4.0"
4+
end
5+
end

rspec-uuid.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package_name = File.basename(__FILE__).split(".")[0]
2-
require File.expand_path("lib/#{package_name}/version", __dir__)
2+
load Dir.glob("lib/**/version.rb")[0]
33

4-
package = RSpecUUID
4+
package = RSpec::UUID
55

66

77
Gem::Specification.new do |s|

0 commit comments

Comments
 (0)