class Foodtaster::RSpec::Matchers::UserMatcher
Public Class Methods
new(username)
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 5 def initialize(username) @username = username end
Public Instance Methods
description()
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 50 def description ["have user '#{@username}'", @group && "in group #{@group}"].delete_if { |a| !a }.join(" ") end
failure_message_for_should()
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 32 def failure_message_for_should msg = ["expected that #{@vm.name} should have user '#{@username}'"] if @group msg << "in group #{@group.inspect}" if @results.key?(:group) && !@results[:group] msg << " but actual user groups are:\n#{@actual_groups.join(", ")}\n" end end msg.join(" ") end
failure_message_for_should_not()
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 46 def failure_message_for_should_not "expected that #{@vm.name} should not have user '#{@username}'" end
in_group(group)
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 26 def in_group(group) @group = group self end
matches?(vm)
click to toggle source
# File lib/foodtaster/rspec/matchers/user_matcher.rb, line 9 def matches?(vm) @vm = vm @results = {} unless vm.execute("cat /etc/passwd | cut -d: -f1 | grep \"\\<#{@username}\\>\"").successful? @results[:user] = false return false end if @group @actual_groups = vm.execute("groups #{@username}").stdout.to_s.chomp.split(" ")[2..-1] || [] @results[:group] = !!@actual_groups.include?(@group) end @results.values.all? end