Class: RSpecUUID::Matchers::UUIDMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-uuid/matchers.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



11
12
13
# File 'lib/rspec-uuid/matchers.rb', line 11

def description
  "be a UUID"
end

#failure_messageObject



15
16
17
# File 'lib/rspec-uuid/matchers.rb', line 15

def failure_message
  "expected a UUID"
end

#failure_message_when_negatedObject



19
20
21
# File 'lib/rspec-uuid/matchers.rb', line 19

def failure_message_when_negated
  "did not expect a UUID"
end

#matches?(obj) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# File 'lib/rspec-uuid/matchers.rb', line 4

def matches?(obj)
  return false unless obj.is_a?(String)

  # https://www.uuidtools.com/what-is-uuid
  obj.match? /^\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/
end