Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Faker::Computer #1948

Merged
merged 15 commits into from
May 17, 2020
64 changes: 64 additions & 0 deletions lib/faker/default/computer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

module Faker
class Computer < Base
class << self
##
# Produces the name of a computer platform.
#
# @return [String]
#
# @example
# Faker::Computer.platform #=> "Linux"
#
# @faker.version next
def platform
fetch('computer.platform')
end

##
# Produces the name of a computer type.
#
# @return [String]
#
# @example
# Faker::Computer.type #=> "server"
#
# @faker.version next
def type
fetch('computer.type')
end

##
# Produces the name of a computer os.
#
# @param platform [String] optionally specify the platform
# @return [String]
#
# @example
# Faker::Computer.os #=> "RHEL 6.10"
#
# @faker.version next
def os(platform:)
platform = self.platform unless fetch_all('computer.platform').include?(platform)
platform = search_format(platform)
fetch("computer.#{platform}.os")
end

##
# Produces a string with computer platform and os
#
# @return [String]
#
# @example
# Faker::Computer.stack #=> "Linux, RHEL 6.10"
#
# @faker.version next
def stack
platform = self.platform
os = fetch("computer.os.#{platform.downcase}")
"#{platform}, #{os}"
end
end
end
end
36 changes: 36 additions & 0 deletions lib/locales/en/computer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
en:
faker:
computer:
type:
- server
- workstation
platform:
- Linux
- macOS
- Windows
os:
linux:
- RHEL 6.10
- RHEL 7.7
- CentOS 8
- CentOS 7
- CentOS 6
- Debian 10.10.3
- Debian 9.9.10
- Ubuntu Server 18.04
- Ubuntu Server 19.10
- ArchLinux 2020.02.01
- openSUSE Leap 15.1
- Ubuntu Desktop 18.04
- Ubuntu Desktop 19.10
macos:
- Catalina (10.15)
- Mojave (10.14)
- High Sierra (10.13)
windows:
- Windows 10
- Windows 8.1
- Windows 7
- Windows Server 2019
- Windows Server 2016
- Windows Server 2012 R2
33 changes: 33 additions & 0 deletions test/faker/default/test_faker_computer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerComputer < Test::Unit::TestCase
def setup
@tester = Faker::Computer
@platforms = Faker::Base.fetch_all('computer.platform')
end

def test_type
assert @tester.type.match(/\w+/)
end

def test_platform
assert @tester.platform.match(/(\w+ ?){1,3}/)
end

def test_stack
# puts @tester.stack
assert stack = @tester.stack
.match(/\A(?<platform>([[:alnum:]]+\s?){1,5}), (?<os>([[:alnum:]]+-?.?\)?\(?\s?){1,5})\z/)

platform = stack[:platform]
search_format_platform = platform.downcase
os = stack[:os]

oses = Faker::Base.fetch_all("computer.os.#{search_format_platform}")

assert @platforms.include?(platform)
assert oses.include?(os)
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
add_filter ['.bundle', 'lib/extensions', 'test']
end

require 'test/support/assert_not_english'
require_relative 'support/assert_not_english'
require 'minitest/autorun'
require 'test/unit'
require 'rubygems'
Expand Down