Module: Operations::TestHelpers
- Defined in:
- lib/operations/test_helpers.rb
Overview
This module contains helpers for simplifaction of testing of operation-related concerns.
Class Method Summary collapse
Instance Method Summary collapse
-
#policy_errors(policy, contract = Operations::TestHelpers.empty_contract, **context) ⇒ Object
Works exactly the same way as #precondition_errors but for policies.
-
#precondition_errors(precondition, contract = Operations::TestHelpers.empty_contract, **context) ⇒ Object
Used to test messages generated by preconditions If one calls ‘precondition.call` intests and it returns `Failure` there is no way to check is a proper text message will be rendered.
Class Method Details
.empty_contract ⇒ Object
13 14 15 |
# File 'lib/operations/test_helpers.rb', line 13 def self.empty_contract @empty_contract ||= OperationContract.build { schema { nil } } end |
Instance Method Details
#policy_errors(policy, contract = Operations::TestHelpers.empty_contract, **context) ⇒ Object
Works exactly the same way as #precondition_errors but for policies.
63 64 65 66 67 68 69 70 |
# File 'lib/operations/test_helpers.rb', line 63 def policy_errors(policy, contract = Operations::TestHelpers.empty_contract, **context) component = Operations::Components::Policies.new( [policy], message_resolver: contract. ) result = component.call({}, context) result.errors.to_h end |
#precondition_errors(precondition, contract = Operations::TestHelpers.empty_contract, **context) ⇒ Object
Used to test messages generated by preconditions If one calls ‘precondition.call` intests and it returns `Failure` there is no way to check is a proper text message will be rendered.
We need to pass contract since preconditions are using the contract’s message rendering and we want to ensure that the translation is placed correctly in the scope of the operation.
50 51 52 53 54 55 56 57 |
# File 'lib/operations/test_helpers.rb', line 50 def precondition_errors(precondition, contract = Operations::TestHelpers.empty_contract, **context) component = Operations::Components::Preconditions.new( [precondition], message_resolver: contract. ) result = component.call({}, context) result.errors.to_h end |