forked from dpep/rspec-uuid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
require "rspec/expectations" | ||
|
||
RSpec::Matchers.define :be_a_uuid do |version: nil| | ||
match do |actual| | ||
raise ArgumentError if @version && version | ||
|
||
return false unless actual.is_a?(String) | ||
|
||
# https://www.uuidtools.com/what-is-uuid | ||
matches = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/ | ||
return false unless matches | ||
|
||
version ||= @version | ||
if version | ||
# 1st nibble of 3rd section | ||
@actual_version = matches[1].to_i(16) >> 12 | ||
|
||
version == @actual_version | ||
else | ||
true | ||
end | ||
end | ||
|
||
chain :of_version do |version| | ||
@version = version | ||
end | ||
|
||
description do | ||
version ? "a UUID v#{version}" : "a UUID" | ||
end | ||
|
||
failure_message do | ||
if @actual_version | ||
"expected #{description}, found a UUID v#{@actual_version}" | ||
else | ||
"expected #{description}" | ||
end | ||
end | ||
|
||
failure_message_when_negated do | ||
"did not expect #{description}" | ||
end | ||
end | ||
|
||
RSpec::Matchers.alias_matcher :a_uuid, :be_a_uuid | ||
require "rspec/uuid" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "rspec/expectations" | ||
|
||
RSpec::Matchers.define :be_a_uuid do |version: nil| | ||
match do |actual| | ||
raise ArgumentError if @version && version | ||
|
||
return false unless actual.is_a?(String) | ||
|
||
# https://www.uuidtools.com/what-is-uuid | ||
matches = actual.match /^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/ | ||
return false unless matches | ||
|
||
version ||= @version | ||
if version | ||
# 1st nibble of 3rd section | ||
@actual_version = matches[1].to_i(16) >> 12 | ||
|
||
version == @actual_version | ||
else | ||
true | ||
end | ||
end | ||
|
||
chain :of_version do |version| | ||
@version = version | ||
end | ||
|
||
description do | ||
version ? "a UUID v#{version}" : "a UUID" | ||
end | ||
|
||
failure_message do | ||
if @actual_version | ||
"expected #{description}, found a UUID v#{@actual_version}" | ||
else | ||
"expected #{description}" | ||
end | ||
end | ||
|
||
failure_message_when_negated do | ||
"did not expect #{description}" | ||
end | ||
end | ||
|
||
RSpec::Matchers.alias_matcher :a_uuid, :be_a_uuid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module RSpec | ||
module UUID | ||
VERSION = "0.4.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters