Class: Synthra::Generator::Modes::InvalidMode

Inherits:
BaseMode
  • Object
show all
Defined in:
lib/synthra/generator/modes.rb

Overview

Invalid mode - intentionally wrong data

Generates intentionally invalid values (wrong types, malformed data) useful for testing validation logic.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Synthra::Generator::Modes::BaseMode

Instance Method Details

#generate(type_instance, args, context = nil) ⇒ Object

Generate an invalid value

Parameters:

  • type_instance (Base)

    type generator instance

  • args (Hash)

    type arguments

Returns:

  • (Object)

    invalid value



195
196
197
198
# File 'lib/synthra/generator/modes.rb', line 195

def generate(type_instance, args, context = nil)
  context ||= Generator::Context.new
  type_instance.generate_invalid(@rng, context, args)
end

#invalid_emailObject

Get an invalid email value

Returns a value that is not a valid email address.

Returns:

  • (Object)

    invalid value (malformed email, nil, number)



232
233
234
235
236
237
238
239
240
241
242
# File 'lib/synthra/generator/modes.rb', line 232

def invalid_email
  @rng.sample([
    "notanemail",
    "@missing.local",
    "missing@",
    "double@@at.com",
    "spaces in@email.com",
    nil,
    123
  ])
end

#invalid_numberObject

Get an invalid number value

Returns a value that is not a valid number.

Returns:

  • (Object)

    invalid value (string, nil, array)



220
221
222
# File 'lib/synthra/generator/modes.rb', line 220

def invalid_number
  @rng.sample(["not a number", nil, "NaN", "Infinity", "", []])
end

#invalid_stringObject

Get an invalid string value

Returns a value that is not a valid string.

Returns:

  • (Object)

    invalid value (nil, number, array, hash, boolean)



208
209
210
# File 'lib/synthra/generator/modes.rb', line 208

def invalid_string
  @rng.sample([nil, 123, [], {}, true])
end

#invalid_uuidObject

Get an invalid UUID value

Returns a value that is not a valid UUID.

Returns:

  • (Object)

    invalid value (string, nil, number)



252
253
254
255
256
257
258
259
260
# File 'lib/synthra/generator/modes.rb', line 252

def invalid_uuid
  @rng.sample([
    "not-a-uuid",
    "12345",
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    nil,
    123
  ])
end