lib/minitest-chef-handler/assertions.rb in minitest-chef-handler-1.0.1 vs lib/minitest-chef-handler/assertions.rb in minitest-chef-handler-1.0.2
- old
+ new
@@ -1,5 +1,7 @@
+require 'set'
+
module MiniTest
module Chef
module Assertions
def self.resource_exists(name, options)
@@ -31,18 +33,20 @@
refute service.enabled, "Expected service '#{service.name}' to not be enabled"
service
end
def assert_group_includes(members, group)
- members = [members] unless members.respond_to?(:&)
- assert group.members & members == members, "Expected group '#{group.name}' to include members: #{members.join(', ')}"
+ members = Set.new(Array(members))
+ assert Set.new(group.members) & members == members,
+ "Expected group '#{group.name}' to include members: #{members.to_a.join(', ')}"
group
end
def refute_group_includes(members, group)
- members = [members] unless members.respond_to?(:&)
- refute group.members & members == members, "Expected group '#{group.name}' not to include members: #{members.join(', ')}"
+ members = Set.new(Array(members))
+ refute Set.new(group.members) & members == members,
+ "Expected group '#{group.name}' not to include members: #{members.to_a.join(', ')}"
group
end
def assert_includes_content(file, content)
assert File.read(file.path).include?(content), "Expected file '#{file.path}' to include the specified content"
@@ -123,24 +127,31 @@
refute service.running, "Expected service '#{service.name}' not to be running"
service
end
def assert_directory(dir, *args)
- assert File.directory?(dir), "Expected #{dir} is be a directory"
+ assert File.directory?(dir), "Expected #{dir} to be a directory"
assert_acl(dir, *args)
end
def assert_file(file, *args)
- assert File.file?(file), "Expected #{file} is be a file"
+ assert File.file?(file), "Expected #{file} to be a file"
assert_acl(file, *args)
end
def assert_acl(file, owner, group, mode)
- file(file).
- must_have(:owner, owner).
- must_have(:group, group).
- must_have(:mode, mode)
+ unless File.directory?(file)
+ file(file).
+ must_have(:owner, owner).
+ must_have(:group, group).
+ must_have(:mode, mode)
+ else
+ directory(file).
+ must_have(:owner, owner).
+ must_have(:group, group).
+ must_have(:mode, mode)
+ end
end
def assert_symlinked_file(file, *args)
assert File.symlink?(file), "Expected #{file} to be a symlink"
assert File.read(file, 1), "Expected #{file} to be linked to an existing file"
@@ -163,8 +174,14 @@
out = `#{command} 2>&1`
assert $?.success?, "#{text}, but failed with: #{out}"
out
end
+ def refute_sh(command, text=nil)
+ text ||= "Expected #{command} not to succeed"
+ out = `#{command} 2>&1`
+ assert !$?.success?, "#{text}, but succeeded with: #{out}"
+ out
+ end
end
end
end