class RSpec::SleepingKingStudios::Matchers::Core::BeAUuidMatcher
Matcher for testing whether an object is a UUID string.
@since 2.5.0
Public Instance Methods
description()
click to toggle source
(see BaseMatcher#description
)
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 12 def description 'be a UUID' end
failure_message()
click to toggle source
(see BaseMatcher#failure_message
)
Calls superclass method
RSpec::SleepingKingStudios::Matchers::BaseMatcher#failure_message
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 17 def failure_message message = super() + ', but ' return message + 'was not a String' unless string? return message + 'was too short' if too_short? return message + 'was too long' if too_long? return message + 'has invalid characters' if invalid_characters? return message + 'the format is invalid' unless valid_format? message end
matches?(actual)
click to toggle source
Checks if the object is a UUID string.
@param [Object] actual The object to check.
@return [Boolean] true if the object is a string with the correct format;
otherwise false.
Calls superclass method
RSpec::SleepingKingStudios::Matchers::BaseMatcher#matches?
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 39 def matches?(actual) super string? && valid_length? && valid_characters? && valid_format? end
Private Instance Methods
invalid_characters?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 47 def invalid_characters? @invalid_characters ||= @actual.match?(/[^A-Fa-f0-9\-]/) end
string?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 51 def string? @string ||= @actual.is_a?(String) end
too_long?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 55 def too_long? @too_long ||= @actual.length > 36 end
too_short?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 59 def too_short? @too_short ||= @actual.length < 36 end
uuid_format()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 63 def uuid_format chars = '[A-Fa-f0-9\-]' /\A#{chars}{8}-#{chars}{4}-#{chars}{4}-#{chars}{4}-#{chars}{12}\z/ end
valid_characters?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 69 def valid_characters? !invalid_characters? end
valid_format?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 73 def valid_format? @valid_format || @actual.match?(uuid_format) end
valid_length?()
click to toggle source
# File lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb, line 77 def valid_length? !too_short? && !too_long? end