lib/minitest-chef-handler/resources.rb in minitest-chef-handler-0.6.9 vs lib/minitest-chef-handler/resources.rb in minitest-chef-handler-1.0.0
- old
+ new
@@ -33,15 +33,21 @@
register_resource(:ifconfig, :device)
register_resource(:mount, :device)
::Chef::Resource.class_eval do
- def with(attribute, values)
+ def with(attribute, values, failure_message=nil)
mt = Object.extend(MiniTest::Assertions)
actual_values = resource_value(attribute)
- mt.assert_equal values, actual_values,
- "The #{resource_name} does not have the expected #{attribute}"
+ details = " #{path}" if respond_to?(:path)
+
+ failure_message ||= "The #{resource_name}#{details} does not have the expected #{attribute}"
+ if attribute == :mode
+ values = values.to_s(8) if values.is_a?(Integer) # better diff since 0755 would be shown as 493
+ values = values.to_s.sub(/^0+/, "") # better diff, ignore leading zeros
+ end
+ mt.assert_equal values, actual_values, failure_message
self
end
alias :and :with
alias :must_have :with
@@ -50,10 +56,10 @@
def resource_value(attribute)
case attribute
when :mode
return nil unless mode
- mode.kind_of?(Integer) ? mode.to_s(8) : mode.to_s
+ mode.kind_of?(Integer) ? mode.to_s(8) : mode.to_s.sub(/^0+/, "")
when :owner || :user
return nil unless owner
owner.is_a?(Integer) ? Etc.getpwuid(owner).name : Etc.getpwnam(owner).name
when :group
return nil unless group