Class: RSpec::SleepingKingStudios::Matchers::Core::BeAUuidMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb

Overview

Matcher for testing whether an object is a UUID string.

Since:

  • 2.5.0

Constant Summary

Constants included from Description

Description::DEFAULT_EXPECTED_ITEMS

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual

Instance Method Summary collapse

Methods inherited from BaseMatcher

#does_not_match?, #failure_message_when_negated

Instance Method Details

#descriptionObject

Since:

  • 2.5.0



12
13
14
# File 'lib/rspec/sleeping_king_studios/matchers/core/be_a_uuid_matcher.rb', line 12

def description
  'be a UUID'
end

#failure_messageObject

Message for when the object does not match, but was expected to. Make sure to always call #matches? first to set up the matcher state.

Since:

  • 2.5.0



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Boolean

Checks if the object is a UUID string.

Parameters:

  • actual (Object)

    The object to check.

Returns:

  • (Boolean)

    true if the object is a string with the correct format; otherwise false.

Since:

  • 2.5.0



39
40
41
42
43
# 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