Module: Trailblazer::Test::Assertion
- Defined in:
- lib/trailblazer/test/assertion.rb,
lib/trailblazer/test/assertion/assert_fail.rb,
lib/trailblazer/test/assertion/assert_pass.rb,
lib/trailblazer/test/assertion/assert_exposes.rb
Overview
Top-level entry points for end users. These methods expose the end user syntax, not the logic.
Defined Under Namespace
Modules: Activity, AssertExposes, AssertFail, AssertPass
Constant Summary collapse
- SUCCESS_TERMINI =
DISCUSS: where should this be defined?
[:success, :pass_fast]
Class Method Summary collapse
-
.actual(asserted, reader, name) ⇒ Object
# Read the actual value from the asserted object (e.g. a model).
-
.expected(asserted, value, actual) ⇒ Object
Evaluate value if it’s a lambda, and let the caller know whether we need an assert_equal or an assert.
-
.invoke_operation(operation, ctx) ⇒ Object
Invoker for Operation.
-
.invoke_operation_with_wtf(operation, ctx) ⇒ Object
Invoker with debugging for Operation.
- .module!(receiver, activity: false, suite: false, spec: true) ⇒ Object
Instance Method Summary collapse
-
#assert_fail(activity, options, *args, invoke: Assertion.method(:invoke_operation), **kws, &block) ⇒ Object
DISCUSS: move to Assertion::Minitest? Test case instance method.
- #assert_fail?(*args, **options, &block) ⇒ Boolean
-
#assert_pass(activity, options, invoke: Assertion.method(:invoke_operation), model_at: :model, **kws, &block) ⇒ Object
DISCUSS: move to Assertion::Minitest? Test case instance method.
- #assert_pass?(*args, **options, &block) ⇒ Boolean
Class Method Details
.actual(asserted, reader, name) ⇒ Object
# Read the actual value from the asserted object (e.g. a model).
45 46 47 |
# File 'lib/trailblazer/test/assertion.rb', line 45 def self.actual(asserted, reader, name) reader ? asserted.public_send(reader, name) : asserted.public_send(name) end |
.expected(asserted, value, actual) ⇒ Object
Evaluate value if it’s a lambda, and let the caller know whether we need an assert_equal or an assert.
40 41 42 |
# File 'lib/trailblazer/test/assertion.rb', line 40 def self.expected(asserted, value, actual) value.is_a?(Proc) ? [value.(actual: actual, asserted: asserted), false] : [value, true] end |
.invoke_operation(operation, ctx) ⇒ Object
Invoker for Operation
24 25 26 27 28 |
# File 'lib/trailblazer/test/assertion.rb', line 24 def self.invoke_operation(operation, ctx) result = operation.call(ctx) return result.terminus, result # translate the holy {Operation::Result} object back to a normal "circuit interface" return value. end |
.invoke_operation_with_wtf(operation, ctx) ⇒ Object
Invoker with debugging for Operation
32 33 34 35 36 |
# File 'lib/trailblazer/test/assertion.rb', line 32 def self.invoke_operation_with_wtf(operation, ctx) result = operation.wtf?(ctx) return result.terminus, result end |
.module!(receiver, activity: false, suite: false, spec: true) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/trailblazer/test/assertion.rb', line 6 def self.module!(receiver, activity: false, suite: false, spec: true) modules = [Helper::MockStep, AssertExposes] if suite modules += [Suite, Suite::Spec] if spec modules += [Suite, Suite::Test] if suite && !spec else modules += [Assertion] end modules += [Assertion::Activity] if activity receiver.include(*modules.reverse) end |
Instance Method Details
#assert_fail(activity, options, *args, invoke: Assertion.method(:invoke_operation), **kws, &block) ⇒ Object
DISCUSS: move to Assertion::Minitest? Test case instance method. Specific to Minitest.
64 65 66 |
# File 'lib/trailblazer/test/assertion.rb', line 64 def assert_fail(activity, , *args, invoke: Assertion.method(:invoke_operation), **kws, &block) AssertFail.(activity, , *args, test: self, user_block: block, invoke: invoke, **kws) # Forward {#assert_fail} to {AssertFail.call} or wherever your implementation sits. end |
#assert_fail?(*args, **options, &block) ⇒ Boolean
72 73 74 |
# File 'lib/trailblazer/test/assertion.rb', line 72 def assert_fail?(*args, **, &block) assert_fail(*args, **, invoke: Assertion.method(:invoke_operation_with_wtf), &block) end |
#assert_pass(activity, options, invoke: Assertion.method(:invoke_operation), model_at: :model, **kws, &block) ⇒ Object
DISCUSS: move to Assertion::Minitest? Test case instance method. Specific to Minitest.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trailblazer/test/assertion.rb', line 51 def assert_pass(activity, , invoke: Assertion.method(:invoke_operation), model_at: :model, **kws, &block) # DISCUSS: {:model_at} and {:invoke_method} block actual attributes. AssertPass.(activity, , test: self, user_block: block, expected_model_attributes: kws, model_at: model_at, invoke: invoke, ) # Forward {#assert_pass} to {AssertPass.call} or wherever your implementation sits. end |
#assert_pass?(*args, **options, &block) ⇒ Boolean
68 69 70 |
# File 'lib/trailblazer/test/assertion.rb', line 68 def assert_pass?(*args, **, &block) assert_pass(*args, **, invoke: Assertion.method(:invoke_operation_with_wtf), &block) end |