diff --git a/lib/faker/default/computer.rb b/lib/faker/default/computer.rb new file mode 100644 index 0000000000..0e85ee5f38 --- /dev/null +++ b/lib/faker/default/computer.rb @@ -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 diff --git a/lib/locales/en/computer.yml b/lib/locales/en/computer.yml new file mode 100644 index 0000000000..d2e429c709 --- /dev/null +++ b/lib/locales/en/computer.yml @@ -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 diff --git a/test/faker/default/test_faker_computer.rb b/test/faker/default/test_faker_computer.rb new file mode 100644 index 0000000000..a1a9501f9c --- /dev/null +++ b/test/faker/default/test_faker_computer.rb @@ -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(?([[:alnum:]]+\s?){1,5}), (?([[: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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 57e4936d51..975990d636 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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'