Class: SpecForge::Error::InvalidFakerClassError

Inherits:
Error
  • Object
show all
Defined in:
lib/spec_forge/error.rb

Overview

Raised when a provided Faker class name doesn't exist Provides helpful suggestions for similar class names

Examples:

Attribute::Faker.new("faker.invalid.method")
# => InvalidFakerClassError: Undefined Faker class "invalid". Did you mean? name, games, ...

Constant Summary collapse

CLASS_CHECKER =

A spell checker for Faker classes

Returns:

  • (DidYouMean::SpellChecker)
DidYouMean::SpellChecker.new(
  dictionary: Faker::Base.descendants.map { |c| c.to_s.downcase.gsub!("::", ".") }
)

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ InvalidFakerClassError

Returns a new instance of InvalidFakerClassError.



26
27
28
29
30
31
32
33
34
35
# File 'lib/spec_forge/error.rb', line 26

def initialize(input)
  corrections = CLASS_CHECKER.correct(input)

  super(<<~STRING.chomp
    Undefined Faker class "#{input}". #{DidYouMean::Formatter.message_for(corrections)}

    For available classes, please check https://github.com/faker-ruby/faker/blob/main/GENERATORS.md.
  STRING
  )
end