SHARE
TWEET

Untitled

a guest Oct 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Spectator::Matchers
  2.   struct HavePermissionsMatcher(ExpectedType) < Spectator::Matchers::ValueMatcher(ExpectedType)
  3.     def description : String
  4.       "have permissions of #{expected.label}"
  5.     end
  6.  
  7.     # Checks whether the matcher is satisfied with the expression given to it.
  8.     private def match?(actual : Spectator::TestExpression(T)) : Bool forall T
  9.       File.info(actual.value).permissions.value == expected.value
  10.     end
  11.  
  12.     private def failure_message(actual : Spectator::TestExpression(T)) : String forall T
  13.       "#{actual.label} does not have permissions of #{expected.label}"
  14.     end
  15.    
  16.     private def failure_message_when_negated(actual : Spectator::TestExpression(T)) : String
  17.       "#{actual.label} should not have permissions of #{expected.label}"
  18.     end
  19.   end
  20. end
  21.  
  22. macro have_permissions(expected)
  23.   %test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
  24.   ::Spectator::Matchers::HavePermissionsMatcher.new(%test_value)
  25. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top