Class: SpecForge::Error::InvalidFakerMethodError

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

Overview

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

Examples:

Attribute::Faker.new("faker.name.invlaid")
# => InvalidFakerMethodError: Undefined Faker method "invlaid" for "Faker::Name".
                              Did you mean? first_name, last_name, ...

Instance Method Summary collapse

Constructor Details

#initialize(input, klass) ⇒ InvalidFakerMethodError

Returns a new instance of InvalidFakerMethodError.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/spec_forge/error.rb', line 48

def initialize(input, klass)
  spell_checker = DidYouMean::SpellChecker.new(dictionary: klass.public_methods)
  corrections = spell_checker.correct(input)

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

    For available methods for this class, please check https://github.com/faker-ruby/faker#generators.
  STRING
  )
end