Class: Synthra::Generator::Modes::InvalidMode
- 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
-
#generate(type_instance, args, context = nil) ⇒ Object
Generate an invalid value.
-
#invalid_email ⇒ Object
Get an invalid email value.
-
#invalid_number ⇒ Object
Get an invalid number value.
-
#invalid_string ⇒ Object
Get an invalid string value.
-
#invalid_uuid ⇒ Object
Get an invalid UUID value.
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
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_email ⇒ Object
Get an invalid email value
Returns a value that is not a valid email address.
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_number ⇒ Object
Get an invalid number value
Returns a value that is not a valid number.
220 221 222 |
# File 'lib/synthra/generator/modes.rb', line 220 def invalid_number @rng.sample(["not a number", nil, "NaN", "Infinity", "", []]) end |
#invalid_string ⇒ Object
Get an invalid string value
Returns a value that is not a valid string.
208 209 210 |
# File 'lib/synthra/generator/modes.rb', line 208 def invalid_string @rng.sample([nil, 123, [], {}, true]) end |
#invalid_uuid ⇒ Object
Get an invalid UUID value
Returns a value that is not a valid UUID.
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 |