diff --git a/lib/bundles/inspec-artifact/cli.rb b/lib/bundles/inspec-artifact/cli.rb index 9dd68baba..024bac89a 100644 --- a/lib/bundles/inspec-artifact/cli.rb +++ b/lib/bundles/inspec-artifact/cli.rb @@ -154,17 +154,17 @@ module Artifact p = Pathname.new(path_to_profile) p = p.join('inspec.yml') if not p.exist? - fail "#{path_to_profile} doesn't appear to be a valid Inspec profile" + raise "#{path_to_profile} doesn't appear to be a valid Inspec profile" end yaml = YAML.load_file(p.to_s) yaml = yaml.to_hash if not yaml.key? 'name' - fail 'Profile is invalid, name is not defined' + raise 'Profile is invalid, name is not defined' end if not yaml.key? 'version' - fail 'Profile is invalid, version is not defined' + raise 'Profile is invalid, version is not defined' end rescue => e # rewrap it and pass it up to the CLI @@ -212,15 +212,15 @@ module Artifact public_keyfile = "#{file_keyname}.pem.pub" puts "Looking for #{public_keyfile} to verify artifact" if not File.exist? public_keyfile - fail "Can't find #{public_keyfile}" + raise "Can't find #{public_keyfile}" end if not VALID_PROFILE_DIGESTS.member? file_alg - fail 'Invalid artifact digest algorithm detected' + raise 'Invalid artifact digest algorithm detected' end if not VALID_PROFILE_VERSIONS.member? file_version - fail 'Invalid artifact version detected' + raise 'Invalid artifact version detected' end end diff --git a/lib/bundles/inspec-compliance/http.rb b/lib/bundles/inspec-compliance/http.rb index c02de6d2e..a4788a1c8 100644 --- a/lib/bundles/inspec-compliance/http.rb +++ b/lib/bundles/inspec-compliance/http.rb @@ -38,7 +38,7 @@ module Compliance # post a file def self.post_file(url, headers, file_path, insecure) uri = URI.parse(url) - fail "Unable to parse URL: #{url}" if uri.nil? || uri.host.nil? + raise "Unable to parse URL: #{url}" if uri.nil? || uri.host.nil? http = Net::HTTP.new(uri.host, uri.port) # set connection flags @@ -67,7 +67,7 @@ module Compliance } opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if insecure - fail "Unable to parse URI: #{uri}" if uri.nil? || uri.host.nil? + raise "Unable to parse URI: #{uri}" if uri.nil? || uri.host.nil? res = Net::HTTP.start(uri.host, uri.port, opts) { |http| http.request(req) } diff --git a/lib/bundles/inspec-compliance/target.rb b/lib/bundles/inspec-compliance/target.rb index c850de742..933423928 100644 --- a/lib/bundles/inspec-compliance/target.rb +++ b/lib/bundles/inspec-compliance/target.rb @@ -37,7 +37,7 @@ module Compliance server = 'compliance' msg = "inspec compliance login https://your_compliance_server --user admin --insecure --token 'PASTE TOKEN HERE' " end - fail Inspec::FetcherFailure, < CURRENT_LOCKFILE_VERSION - fail < 0 # ignore empty lines + if !line.strip.empty? # ignore empty lines line_whitespace = line.length - line.lstrip.length min = line_whitespace if min.nil? || line_whitespace < min end diff --git a/lib/inspec/source_reader.rb b/lib/inspec/source_reader.rb index 40d0ccb6e..908b34fd8 100644 --- a/lib/inspec/source_reader.rb +++ b/lib/inspec/source_reader.rb @@ -19,7 +19,7 @@ module Inspec def self.source_reader(version) if version != 1 - fail 'Only source readers version 1 is supported!' + raise 'Only source readers version 1 is supported!' end Inspec::Plugins::SourceReader end diff --git a/lib/matchers/matchers.rb b/lib/matchers/matchers.rb index b125e8807..b972a36cf 100644 --- a/lib/matchers/matchers.rb +++ b/lib/matchers/matchers.rb @@ -105,7 +105,7 @@ RSpec::Matchers.define :be_installed do end chain :by do - fail "[UNSUPPORTED] Please use the new resources 'gem', 'npm' or 'pip'." + raise "[UNSUPPORTED] Please use the new resources 'gem', 'npm' or 'pip'." end chain :with_version do |version| @@ -121,7 +121,7 @@ RSpec::Matchers.define :be_enabled do end chain :with_level do |_level| - fail '[UNSUPPORTED] with level is not supported' + raise '[UNSUPPORTED] with level is not supported' end failure_message do |service| @@ -137,7 +137,7 @@ RSpec::Matchers.define :be_running do end chain :under do |_under| - fail '[UNSUPPORTED] under is not supported' + raise '[UNSUPPORTED] under is not supported' end failure_message do |service| @@ -178,7 +178,7 @@ RSpec::Matchers.define :be_reachable do end chain :with do |_attr| - fail '[UNSUPPORTED] `with` is not supported in combination with `be_reachable`' + raise '[UNSUPPORTED] `with` is not supported in combination with `be_reachable`' end failure_message do |host| @@ -193,7 +193,7 @@ RSpec::Matchers.define :be_resolvable do end chain :by do |_type| - fail "[UNSUPPORTED] `by` is not supported in combination with `be_resolvable`. Please use the following syntax `host('example.com', port: 53, proto: 'udp')`." + raise "[UNSUPPORTED] `by` is not supported in combination with `be_resolvable`. Please use the following syntax `host('example.com', port: 53, proto: 'udp')`." end failure_message do |host| @@ -208,11 +208,11 @@ RSpec::Matchers.define :have_rule do |rule| end chain :with_table do |_table| - fail "[UNSUPPORTED] `with_table` is not supported in combination with `have_rule`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`." + raise "[UNSUPPORTED] `with_table` is not supported in combination with `have_rule`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`." end chain :with_chain do |_chain| - fail "[UNSUPPORTED] `with_table` is not supported in combination with `with_chain`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`." + raise "[UNSUPPORTED] `with_table` is not supported in combination with `with_chain`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`." end end diff --git a/lib/resources/apache_conf.rb b/lib/resources/apache_conf.rb index 228d53816..7cc09dbc9 100644 --- a/lib/resources/apache_conf.rb +++ b/lib/resources/apache_conf.rb @@ -70,7 +70,7 @@ module Inspec::Resources end raw_conf = file.content - if raw_conf.empty? && file.size > 0 + if raw_conf.empty? && !file.empty? return skip_resource("Can't read file \"#{@conf_path}\"") end diff --git a/lib/resources/auditd_conf.rb b/lib/resources/auditd_conf.rb index 5a078d403..8b46911c6 100644 --- a/lib/resources/auditd_conf.rb +++ b/lib/resources/auditd_conf.rb @@ -41,7 +41,7 @@ module Inspec::Resources end content = file.content - if content.empty? && file.size > 0 + if content.empty? && !file.empty? skip_resource "Can't read file '#{@conf_path}'" return @params = {} end diff --git a/lib/resources/auditd_rules.rb b/lib/resources/auditd_rules.rb index dd498f679..e927f716a 100644 --- a/lib/resources/auditd_rules.rb +++ b/lib/resources/auditd_rules.rb @@ -93,7 +93,7 @@ module Inspec::Resources # rubocop:disable Style/MethodName def LIST_RULES return @legacy.LIST_RULES if @legacy - fail 'Using legacy auditd_rules LIST_RULES interface with non-legacy audit package. Please use the new syntax.' + raise 'Using legacy auditd_rules LIST_RULES interface with non-legacy audit package. Please use the new syntax.' end def status(name = nil) diff --git a/lib/resources/bridge.rb b/lib/resources/bridge.rb index da608fed5..635223d8a 100644 --- a/lib/resources/bridge.rb +++ b/lib/resources/bridge.rb @@ -115,7 +115,7 @@ module Inspec::Resources adapter_collection.push(info) if info[:name].casecmp(bridge_name) == 0 end - return nil if bridges.size == 0 + return nil if bridges.empty? warn "[Possible Error] detected multiple bridges interfaces with the name #{bridge_name}" if bridges.size > 1 bridges[0] end diff --git a/lib/resources/etc_group.rb b/lib/resources/etc_group.rb index d3af36199..12e76e9ba 100644 --- a/lib/resources/etc_group.rb +++ b/lib/resources/etc_group.rb @@ -107,7 +107,7 @@ module Inspec::Resources # iterate over each line and filter comments @content.split("\n").each_with_object([]) do |line, lines| grp_info = parse_group_line(line) - lines.push(grp_info) if !grp_info.nil? && grp_info.size > 0 + lines.push(grp_info) if !grp_info.nil? && !grp_info.empty? end end @@ -119,7 +119,7 @@ module Inspec::Resources line, _idx_nl = parse_comment_line(line, opts) x = line.split(':') # abort if we have an empty or comment line - return nil if x.size == 0 + return nil if x.empty? # map data { 'name' => x.at(0), # Name of the group. diff --git a/lib/resources/file.rb b/lib/resources/file.rb index 6785482f6..14836bbb2 100644 --- a/lib/resources/file.rb +++ b/lib/resources/file.rb @@ -61,7 +61,7 @@ module Inspec::Resources end def contain(*_) - fail 'Contain is not supported. Please use standard RSpec matchers.' + raise 'Contain is not supported. Please use standard RSpec matchers.' end def readable?(by_usergroup, by_specific_user) @@ -128,7 +128,7 @@ module Inspec::Resources private def file_permission_granted?(access_type, by_usergroup, by_specific_user) - fail '`file_permission_granted?` is not supported on your OS' if @perms_provider.nil? + raise '`file_permission_granted?` is not supported on your OS' if @perms_provider.nil? if by_specific_user.nil? || by_specific_user.empty? @perms_provider.check_file_permission_by_mask(file, access_type, by_usergroup, by_specific_user) else @@ -154,7 +154,7 @@ module Inspec::Resources when 'execute' 'x' else - fail 'Invalid access_type provided' + raise 'Invalid access_type provided' end end @@ -172,7 +172,7 @@ module Inspec::Resources usergroup = usergroup_for(usergroup, specific_user) flag = permission_flag(access_type) mask = file.unix_mode_mask(usergroup, flag) - fail 'Invalid usergroup/owner provided' if mask.nil? + raise 'Invalid usergroup/owner provided' if mask.nil? (file.mode & mask) != 0 end @@ -197,7 +197,7 @@ module Inspec::Resources class WindowsFilePermissions < FilePermissions def check_file_permission_by_mask(_file, _access_type, _usergroup, _specific_user) - fail '`check_file_permission_by_mask` is not supported on Windows' + raise '`check_file_permission_by_mask` is not supported on Windows' end def check_file_permission_by_user(access_type, user, path) @@ -209,7 +209,7 @@ module Inspec::Resources when 'execute' '@(\'FullControl\', \'Modify\', \'ReadAndExecute\', \'ExecuteFile\')' else - fail 'Invalid access_type provided' + raise 'Invalid access_type provided' end cmd = inspec.command("@(@((Get-Acl '#{path}').access | Where-Object {$_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq '#{user}' }) | Where-Object {($_.FileSystemRights.ToString().Split(',') | % {$_.trim()} | ? {#{access_rule} -contains $_}) -ne $null}) | measure | % { $_.Count }") cmd.stdout.chomp == '0' ? false : true diff --git a/lib/resources/groups.rb b/lib/resources/groups.rb index f64745a03..a94f2a243 100644 --- a/lib/resources/groups.rb +++ b/lib/resources/groups.rb @@ -99,18 +99,18 @@ module Inspec::Resources # verifies if a group exists def exists? - group_info.entries.size > 0 + !group_info.entries.empty? end def gid gids = group_info.gids - if gids.size == 0 + if gids.empty? nil # the default case should be one group elsif gids.size == 1 gids.entries[0] else - fail 'found more than one group with the same name, please use `groups` resource' + raise 'found more than one group with the same name, please use `groups` resource' end end @@ -144,7 +144,7 @@ module Inspec::Resources end def groups - fail 'group provider must implement the `groups` method' + raise 'group provider must implement the `groups` method' end end diff --git a/lib/resources/grub_conf.rb b/lib/resources/grub_conf.rb index 370328dc2..8c393f913 100644 --- a/lib/resources/grub_conf.rb +++ b/lib/resources/grub_conf.rb @@ -38,11 +38,11 @@ class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength @conf_path = path || '/boot/grub/grub.cfg' @defaults_path = '/etc/default/grub' @version = 'grub2' - elsif os[:name] == 'amazon' # rubocop:disable Style/GuardClause + elsif os[:name] == 'amazon' @conf_path = path || '/etc/grub.conf' @version = 'legacy' else - fail UnknownGrubConfig + raise UnknownGrubConfig end end @@ -145,7 +145,7 @@ class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength content = file.content - if content.empty? && file.size > 0 + if content.empty? && !file.empty? skip_resource "Can't read file '#{@conf_path}'" return @params = {} end diff --git a/lib/resources/host.rb b/lib/resources/host.rb index 53a102687..4f4284c25 100644 --- a/lib/resources/host.rb +++ b/lib/resources/host.rb @@ -60,7 +60,7 @@ module Inspec::Resources end def reachable?(port = nil, proto = nil, timeout = nil) - fail "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil? + raise "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil? ping.nil? ? false : ping end diff --git a/lib/resources/inetd_conf.rb b/lib/resources/inetd_conf.rb index ba123a554..b300a6001 100644 --- a/lib/resources/inetd_conf.rb +++ b/lib/resources/inetd_conf.rb @@ -43,7 +43,7 @@ module Inspec::Resources end content = file.content - if content.empty? && file.size > 0 + if content.empty? && !file.empty? skip_resource "Can't read file \"#{@conf_path}\"" return @params = {} end diff --git a/lib/resources/interface.rb b/lib/resources/interface.rb index 91172d275..c6a21f04c 100644 --- a/lib/resources/interface.rb +++ b/lib/resources/interface.rb @@ -121,7 +121,7 @@ module Inspec::Resources adapter_collection.push(info) if info[:name].casecmp(iface) == 0 end - return nil if adapters.size == 0 + return nil if adapters.empty? warn "[Possible Error] detected multiple network interfaces with the name #{iface}" if adapters.size > 1 adapters[0] end diff --git a/lib/resources/json.rb b/lib/resources/json.rb index 69327c31e..301e5ee16 100644 --- a/lib/resources/json.rb +++ b/lib/resources/json.rb @@ -49,7 +49,7 @@ module Inspec::Resources end # check if file is readable - if @file_content.nil? && @file.size > 0 + if @file_content.nil? && !@file.empty? skip_resource "Can't read file \"#{@path}\"" return @params = {} end diff --git a/lib/resources/limits_conf.rb b/lib/resources/limits_conf.rb index a7d9ed447..f10a94e92 100644 --- a/lib/resources/limits_conf.rb +++ b/lib/resources/limits_conf.rb @@ -35,7 +35,7 @@ module Inspec::Resources end content = file.content - if content.empty? && file.size > 0 + if content.empty? && !file.empty? skip_resource "Can't read file \"#{@conf_path}\"" return @params = {} end diff --git a/lib/resources/login_def.rb b/lib/resources/login_def.rb index 6a5b913b7..b9f77b4b1 100644 --- a/lib/resources/login_def.rb +++ b/lib/resources/login_def.rb @@ -47,7 +47,7 @@ module Inspec::Resources end content = file.content - if content.empty? && file.size > 0 + if content.empty? && !file.empty? skip_resource "Can't read file \"#{@conf_path}\"" return @params = {} end diff --git a/lib/resources/mysql_conf.rb b/lib/resources/mysql_conf.rb index ddbef18ba..0eee7444c 100644 --- a/lib/resources/mysql_conf.rb +++ b/lib/resources/mysql_conf.rb @@ -73,7 +73,7 @@ module Inspec::Resources return skip_resource "Can't find file \"#{@conf_path}\"" end raw_conf = read_file(@conf_path) - if raw_conf.empty? && inspec.file(@conf_path).size > 0 + if raw_conf.empty? && !inspec.file(@conf_path).empty? return skip_resource("Can't read file \"#{@conf_path}\"") end diff --git a/lib/resources/ntp_conf.rb b/lib/resources/ntp_conf.rb index 4ead17246..4aca8c3b6 100644 --- a/lib/resources/ntp_conf.rb +++ b/lib/resources/ntp_conf.rb @@ -43,7 +43,7 @@ module Inspec::Resources end content = inspec.file(@conf_path).content - if content.empty? && inspec.file(@conf_path).size > 0 + if content.empty? && !inspec.file(@conf_path).empty? skip_resource "Can't read file \"#{@conf_path}\"" return @params = {} end diff --git a/lib/resources/packages.rb b/lib/resources/packages.rb index 7668a4721..d3bae2e8e 100644 --- a/lib/resources/packages.rb +++ b/lib/resources/packages.rb @@ -50,7 +50,7 @@ module Inspec::Resources elsif p.class == Regexp p else - fail 'invalid name argument to packages resource, please use a "string" or /regexp/' + raise 'invalid name argument to packages resource, please use a "string" or /regexp/' end end @@ -64,7 +64,7 @@ module Inspec::Resources if os.debian? command = "dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\\n'" else - fail "packages resource is not yet supported on #{os.name}" + raise "packages resource is not yet supported on #{os.name}" end build_package_list(command) end diff --git a/lib/resources/parse_config.rb b/lib/resources/parse_config.rb index c775a0326..45f5665de 100644 --- a/lib/resources/parse_config.rb +++ b/lib/resources/parse_config.rb @@ -76,7 +76,7 @@ module Inspec::Resources return skip_resource "Can't find file \"#{conf_path}\"" end @content = read_file(conf_path).to_s - if @content.empty? && inspec.file(conf_path).size > 0 + if @content.empty? && !inspec.file(conf_path).empty? return skip_resource "Can't read file \"#{conf_path}\"" end diff --git a/lib/resources/port.rb b/lib/resources/port.rb index f978ed21e..90291601f 100644 --- a/lib/resources/port.rb +++ b/lib/resources/port.rb @@ -45,7 +45,7 @@ module Inspec::Resources .add(:protocols, field: 'protocol', style: :simple) .add(:processes, field: 'process', style: :simple) .add(:pids, field: 'pid', style: :simple) - .add(:listening?) { |x| x.entries.length > 0 } + .add(:listening?) { |x| !x.entries.empty? } filter.connect(self, :info) def to_s @@ -169,7 +169,7 @@ module Inspec::Resources ports = [] # check that lsof is available, otherwise fail - fail 'Please ensure `lsof` is available on the machine.' if !inspec.command(@lsof.to_s).exist? + raise 'Please ensure `lsof` is available on the machine.' if !inspec.command(@lsof.to_s).exist? # -F p=pid, c=command, P=protocol name, t=type, n=internet addresses # see 'OUTPUT FOR OTHER PROGRAMS' in LSOF(8) diff --git a/lib/resources/postgres_conf.rb b/lib/resources/postgres_conf.rb index 296d94f5e..8405f4601 100644 --- a/lib/resources/postgres_conf.rb +++ b/lib/resources/postgres_conf.rb @@ -65,7 +65,7 @@ module Inspec::Resources return skip_resource "Can't find file \"#{@conf_path}\"" end raw_conf = read_file(@conf_path) - if raw_conf.empty? && inspec.file(@conf_path).size > 0 + if raw_conf.empty? && !inspec.file(@conf_path).empty? return skip_resource("Can't read file \"#{@conf_path}\"") end diff --git a/lib/resources/security_policy.rb b/lib/resources/security_policy.rb index b0699fced..d3f409d73 100644 --- a/lib/resources/security_policy.rb +++ b/lib/resources/security_policy.rb @@ -117,7 +117,7 @@ module Inspec::Resources return skip_resource "Can't read security policy" if cmd.exit_status.to_i != 0 @content = cmd.stdout - if @content.empty? && file.size > 0 + if @content.empty? && !file.empty? return skip_resource "Can't read security policy" end @content diff --git a/lib/resources/ssh_conf.rb b/lib/resources/ssh_conf.rb index 24a6dba42..c25749534 100644 --- a/lib/resources/ssh_conf.rb +++ b/lib/resources/ssh_conf.rb @@ -62,7 +62,7 @@ module Inspec::Resources end @content = file.content - if @content.empty? && file.size > 0 + if @content.empty? && !file.empty? return skip_resource "Can't read file \"#{@conf_path}\"" end diff --git a/lib/resources/ssl.rb b/lib/resources/ssl.rb index 6b0cc3f3f..15820f9a2 100644 --- a/lib/resources/ssl.rb +++ b/lib/resources/ssl.rb @@ -52,7 +52,7 @@ class SSL < Inspec.resource(1) elsif inspec.backend.class.to_s == 'Train::Transports::Local::Connection' @host = 'localhost' else - fail 'Cannot determine host for SSL test. Please specify it or use a different target.' + raise 'Cannot determine host for SSL test. Please specify it or use a different target.' end end @port = opts[:port] || 443 diff --git a/lib/resources/users.rb b/lib/resources/users.rb index 16d9dd133..27cd8c1de 100644 --- a/lib/resources/users.rb +++ b/lib/resources/users.rb @@ -242,7 +242,7 @@ module Inspec::Resources def has_authorized_key?(_compare_key) deprecated('has_authorized_key?') - fail NotImplementedError + raise NotImplementedError end def deprecated(name, alternative = nil) @@ -292,7 +292,7 @@ module Inspec::Resources # groups: '', # } def identity(_username) - fail 'user provider must implement the `identity` method' + raise 'user provider must implement the `identity` method' end # returns optional information about a user, eg shell @@ -313,7 +313,7 @@ module Inspec::Resources # returns an array with users def list_users - fail 'user provider must implement the `list_users` method' + raise 'user provider must implement the `list_users` method' end # retuns all aspects of the user as one hash @@ -556,7 +556,7 @@ module Inspec::Resources def parse_windows_account(username) account = username.split('\\') name = account.pop - domain = account.pop if account.size > 0 + domain = account.pop if !account.empty? [name, domain] end @@ -565,7 +565,7 @@ module Inspec::Resources name, _domain = parse_windows_account(username) return if collect_user_details.nil? res = collect_user_details.select { |user| user[:username] == name } - res[0] if res.length > 0 + res[0] if !res.empty? end def list_users diff --git a/lib/resources/xinetd.rb b/lib/resources/xinetd.rb index 83344dfa1..0fe390050 100644 --- a/lib/resources/xinetd.rb +++ b/lib/resources/xinetd.rb @@ -57,7 +57,7 @@ module Inspec::Resources end @contents[path] = file.content - if @contents[path].empty? && file.size > 0 + if @contents[path].empty? && !file.empty? return skip_resource "Can't read file \"#{path}\"" end diff --git a/lib/utils/command_wrapper.rb b/lib/utils/command_wrapper.rb index 538a9f90a..da14d79f5 100644 --- a/lib/utils/command_wrapper.rb +++ b/lib/utils/command_wrapper.rb @@ -9,20 +9,20 @@ class CommandWrapper def self.wrap(cmd, options) unless options.is_a?(Hash) - fail 'All options for the command wrapper must be provided as a hash. '\ + raise 'All options for the command wrapper must be provided as a hash. '\ "You entered: #{options.inspect}. Please consult the documentation." end wrap = options[:wrap] if !wrap.nil? && !wrap.is_a?(Proc) - fail "Called command wrapper with wrap: #{wrap.inspect}. It must be called with a Proc." + raise "Called command wrapper with wrap: #{wrap.inspect}. It must be called with a Proc." elsif !wrap.nil? return wrap.call(cmd) end shell = options[:shell] unless UNIX_SHELLS.include?(shell) - fail "Don't know how to wrap commands for shell: #{shell.inspect}." + raise "Don't know how to wrap commands for shell: #{shell.inspect}." end path = options[:path] || shell diff --git a/lib/utils/filter.rb b/lib/utils/filter.rb index 74980b9ca..e01929ee5 100644 --- a/lib/utils/filter.rb +++ b/lib/utils/filter.rb @@ -70,7 +70,7 @@ module FilterTable end def new_entry(*_) - fail "#{self.class} must not be used on its own. It must be inherited "\ + raise "#{self.class} must not be used on its own. It must be inherited "\ 'and the #new_entry method must be implemented. This is an internal '\ 'error and should not happen.' end diff --git a/lib/utils/plugin_registry.rb b/lib/utils/plugin_registry.rb index 76dd43d4e..54c808d67 100644 --- a/lib/utils/plugin_registry.rb +++ b/lib/utils/plugin_registry.rb @@ -39,7 +39,7 @@ class PluginRegistry # # @return [PluginRegistry] plugin registry for this plugin def self.plugin_registry - fail "Plugin #{self} does not implement `self.plugin_registry()`. This method is required" + raise "Plugin #{self} does not implement `self.plugin_registry()`. This method is required" end # Register a new plugin by name @@ -47,7 +47,7 @@ class PluginRegistry # @param [String] the unique name of this plugin # @return [nil] disregard def self.name(name) - fail "Trying to register #{self} with name == nil" if name.nil? + raise "Trying to register #{self} with name == nil" if name.nil? @name = name plugin_registry.registry[name] = self end @@ -72,7 +72,7 @@ class PluginRegistry # @param [String] target to try to resolve # @return [Plugin] instance if it can be resolved, nil otherwise def self.resolve(_target) - fail "Plugin #{self} does not implement `self.resolve(target)`. This method is required" + raise "Plugin #{self} does not implement `self.resolve(target)`. This method is required" end # When a plugin's resolve doesn't lead to the final state, it can diff --git a/lib/utils/simpleconfig.rb b/lib/utils/simpleconfig.rb index 23d5339c8..63c285dbc 100644 --- a/lib/utils/simpleconfig.rb +++ b/lib/utils/simpleconfig.rb @@ -33,7 +33,7 @@ class SimpleConfig raw_data = raw_data.tr(options[:line_separator], "\n") end rest = raw_data - rest = parse_rest(rest, options) while rest.length > 0 + rest = parse_rest(rest, options) until rest.empty? end private diff --git a/tasks/docs.rb b/tasks/docs.rb index 4ac781254..ec099d887 100644 --- a/tasks/docs.rb +++ b/tasks/docs.rb @@ -135,7 +135,7 @@ class ResourceDocs def render_path(path) abs = File.join(@root, path) - fail "Can't find file to render in #{abs}" unless File.file?(abs) + raise "Can't find file to render in #{abs}" unless File.file?(abs) ERB.new(File.read(abs)).result(binding) end diff --git a/tasks/shared.rb b/tasks/shared.rb index 2c1a6704d..124025af1 100644 --- a/tasks/shared.rb +++ b/tasks/shared.rb @@ -28,7 +28,7 @@ end module Verify def self.file(path) return print("\033[32m.\033[0m") if File.file?(path) - fail "Failed to build this step. Looking for file in #{path} but it doesn't exist." + raise "Failed to build this step. Looking for file in #{path} but it doesn't exist." end def self.ok diff --git a/tasks/www.rb b/tasks/www.rb index ff2730871..75b9407f1 100644 --- a/tasks/www.rb +++ b/tasks/www.rb @@ -64,15 +64,15 @@ namespace :www do end unless File.directory?(dst) && File.file?(File.join(dst, 'index.html')) - fail 'It looks like the site was not build. Aborting.' + raise 'It looks like the site was not build. Aborting.' end # check if git exists sh('command -v git >/dev/null 2>&1') || - fail("It looks like `git` isn't installed. It is required to run this build task.") + raise("It looks like `git` isn't installed. It is required to run this build task.") unless sh('git diff-index --quiet HEAD --') - fail 'Please make sure you have no uncommitted changes in this repository.' + raise 'Please make sure you have no uncommitted changes in this repository.' end File.write('www/build/CNAME', 'inspec.io') @@ -86,7 +86,7 @@ namespace :www do current_branch = `git rev-parse --abbrev-ref HEAD`.strip if current_branch.empty? - fail 'Cannot determine current branch to go back to! Aborting.' + raise 'Cannot determine current branch to go back to! Aborting.' end Log.info 'Create empty gh-pages branch' diff --git a/www/lib/sidebar_helpers.rb b/www/lib/sidebar_helpers.rb index 6770c7b4e..60cd047c3 100644 --- a/www/lib/sidebar_helpers.rb +++ b/www/lib/sidebar_helpers.rb @@ -5,7 +5,7 @@ module SidebarHelpers def sidebar_data(sidebar_layout) unless SIDEBAR_LAYOUTS.include?(sidebar_layout) - fail "'#{sidebar_layout}' is not a valid sidebar layout type." + raise "'#{sidebar_layout}' is not a valid sidebar layout type." end data.public_send(:"#{sidebar_layout}_sidebar").sidebar_links.dup diff --git a/www/tutorial/scripts/run_simulator_recording.rb b/www/tutorial/scripts/run_simulator_recording.rb index a59517b12..6e27be5c7 100644 --- a/www/tutorial/scripts/run_simulator_recording.rb +++ b/www/tutorial/scripts/run_simulator_recording.rb @@ -135,7 +135,7 @@ end def generate_simulation_files(simulator, commands, output_dir) require 'docker' - fail "#{simulator} docker image is not available" unless Docker::Image.exist?(simulator) + raise "#{simulator} docker image is not available" unless Docker::Image.exist?(simulator) # start container and get id Docker.options[:read_timeout] = 3 * 60