lib/beaker/host/mac/group.rb in beaker-4.38.1 vs lib/beaker/host/mac/group.rb in beaker-4.39.0

- old
+ new

@@ -4,15 +4,15 @@ # Gets a list of group names on the system # # @param [Proc] block Additional actions or insertions # # @return [Array<String>] The list of group names on the system - def group_list(&block) + def group_list() execute('dscacheutil -q group') do |result| groups = [] result.stdout.each_line do |line| - groups << line.split(': ')[1].strip if line =~ /^name:/ + groups << line.split(': ')[1].strip if /^name:/.match?(line) end yield result if block_given? groups @@ -26,13 +26,13 @@ # # @yield [String] The actual mac dscacheutil output # @return [String] Group information in /etc/group format # @raise [FailTest] Raises an Assertion failure if it can't find the name # queried for in the returned block - def group_get(name, &block) + def group_get(name) execute("dscacheutil -q group -a name #{name}") do |result| - fail_test "failed to get group #{name}" unless result.stdout =~ /^name: #{name}/ + fail_test "failed to get group #{name}" unless /^name: #{name}/.match?(result.stdout) gi = Hash.new # group info result.stdout.each_line { |line| pieces = line.split(': ') gi[pieces[0].to_sym] = pieces[1].strip if pieces[1] != nil } @@ -50,11 +50,11 @@ # @return [String] gid of the group def group_gid(name) gid = -1 execute("dscacheutil -q group -a name #{name}") do |result| result.stdout.each_line { |line| - if line =~ /^gid:/ + if /^gid:/.match?(line) gid = (line[5, line.length - 5]).chomp break end } gid @@ -63,13 +63,13 @@ # Makes sure the group is present, creating it if necessary # # @param [String] name Name of the group # @param [Proc] block Additional actions or insertions - def group_present(name, &block) + def group_present(name) group_exists = false execute("dscacheutil -q group -a name #{name}") do |result| - group_exists = result.stdout =~ /^name: #{name}/ + group_exists = result.stdout.start_with?("name: #{name}") end return if group_exists gid = gid_next