-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Description
Description
When calling klass.name on Faker::Travel::Airport (and potentially other Faker classes), an ArgumentError is raised because the method requires keyword arguments (:size and :region) that are not provided.
This breaks the standard Ruby behavior where Class#name should return the class name as a string.
Steps to Reproduce
require 'faker'
# This should return "Faker::Travel::Airport" but raises ArgumentError
Faker::Travel::Airport.name
# => ArgumentError: missing keywords: :size, :regionExpected Behavior
Faker::Travel::Airport.name
# => "Faker::Travel::Airport"Actual Behavior
Faker::Travel::Airport.name
# => ArgumentError: missing keywords: :size, :regionImpact
This affects any code that:
- Iterates over classes using
ObjectSpace.each_object(Class) - Calls
klass.nameexpecting standard Ruby behavior - Uses metaprogramming that relies on
Class#name
For example:
ObjectSpace.each_object(Class) do |klass|
name = klass.name # Raises ArgumentError when klass is Faker::Travel::Airport
# ...
endEnvironment
- Ruby version: 3.4.7
- Faker version: 3.5.2
- OS: macOS
Suggested Fix
The Faker gem should ensure that:
- The class method
namereturns the class name string (standard Ruby behavior) - Instance methods that generate fake data use different method names (e.g.,
airport_nameinstead ofname) - If the class method must be overridden, it should properly delegate to
Module#name
Workaround
Calling code can wrap klass.name in error handling, but this is a workaround for a bug in Faker:
begin
name = klass.name
rescue ArgumentError, NoMethodError, NameError
next
endMetadata
Metadata
Assignees
Labels
No labels