Method: Faker::Internet::HTTP.status_code

Defined in:
lib/faker/default/internet_http.rb

.status_code(group: nil) ⇒ Integer

Produces an HTTP status code

Examples:

Faker::Internet::HTTP.status_code #=> 418
Faker::Internet::HTTP.status_code(group: :information) #=> 102
Faker::Internet::HTTP.status_code(group: :successful) #=> 200
Faker::Internet::HTTP.status_code(group: :redirect) #=> 306
Faker::Internet::HTTP.status_code(group: :client_error) #=> 451
Faker::Internet::HTTP.status_code(group: :server_error) #=> 502

Returns:

  • (Integer)

Raises:

  • (ArgumentError)

38
39
40
41
42
43
44
# File 'lib/faker/default/internet_http.rb', line 38

def status_code(group: nil)
  return STATUS_CODES[STATUS_CODES_GROUPS.sample].sample unless group

  raise ArgumentError, 'Invalid HTTP status code group' unless STATUS_CODES_GROUPS.include?(group)

  STATUS_CODES[group].sample
end