Class: Hubbado::Policy::RspecMatchers::Deny::DenyMatcher
- Inherits:
-
Object
- Object
- Hubbado::Policy::RspecMatchers::Deny::DenyMatcher
- Defined in:
- lib/hubbado/policy/rspec_matchers/deny.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(action, *args, **kwargs) ⇒ DenyMatcher
constructor
A new instance of DenyMatcher.
- #matches?(policy) ⇒ Boolean
- #with(reason) ⇒ Object
Constructor Details
#initialize(action, *args, **kwargs) ⇒ DenyMatcher
Returns a new instance of DenyMatcher.
10 11 12 13 14 15 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 10 def initialize(action, *args, **kwargs) @action = action @args = args @kwargs = kwargs @reason = :denied end |
Instance Method Details
#description ⇒ Object
46 47 48 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 46 def description "#{@policy.class.name} deny #{@action} with #{@reason}" end |
#failure_message ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 50 def if @incorrect_reason "Expected #{@policy.class.name} to deny #{@action}, with #{@reason} " \ "but it was denied with #{@result.reason}" elsif @missing_translation "Translation missing for policy #{@policy.class.name} and #{@reason}" else "Expected #{@policy.class.name} to deny #{@action}, but it was permitted" end end |
#failure_message_when_negated ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 61 def if @missing_translation "Translation missing for policy #{@policy.class.name} and #{@reason}" else "Expected #{@policy.class.name} to permit #{@action}, but it was denied" end end |
#matches?(policy) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 22 def matches?(policy) @policy = policy @result = policy.send @action, *@args, **@kwargs unless @result.denied? @incorrect_repsonse = true return false end if @reason && @result.reason != @reason @incorrect_reason = true return false end begin @result. rescue I18n::MissingTranslationData @missing_translation = true return false end true end |
#with(reason) ⇒ Object
17 18 19 20 |
# File 'lib/hubbado/policy/rspec_matchers/deny.rb', line 17 def with(reason) @reason = reason self end |