Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement