Skip to content

Commit b4f15b8

Browse files
committed
we can pass assert_pass ..., model_at:, invoke_method:.
1 parent 10e2a94 commit b4f15b8

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

lib/trailblazer/test/assertion.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
module Trailblazer
22
module Test
3+
# Top-level entry points for end users.
4+
# These methods expose the syntax sugar, not the logic.
35
module Assertion
46
# DISCUSS: move to Assertion::Minitest?
57
# Test case instance method. Specific to Minitest.
6-
def assert_pass(activity, options, assertion: AssertPass, **kws, &block)
7-
assertion.(activity, options, test: self, user_block: block, **kws) # Forward {#assert_pass} to {AssertPass.call} or wherever your implementation sits.
8+
def assert_pass(activity, options, assertion: AssertPass, model_at: :model, invoke_method: :call, **kws, &block)
9+
# DISCUSS: {:model_at} and {:invoke_method} block actual attributes.
10+
assertion.(activity, options,
11+
test: self,
12+
user_block: block,
13+
expected_model_attributes: kws,
14+
model_at: model_at,
15+
invoke_method: invoke_method,
16+
) # Forward {#assert_pass} to {AssertPass.call} or wherever your implementation sits.
817
end
918

1019
# DISCUSS: move to Assertion::Minitest?

lib/trailblazer/test/assertion/assert_pass.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Assertion
44
module AssertPass
55
module_function
66

7-
def call(activity, ctx, invoke_method: :call, model_at: :model, test:, user_block:, **expected_model_attributes)
7+
def call(activity, ctx, invoke_method: :call, model_at: :model, test:, user_block:, expected_model_attributes:)
88
result, ctx, kws = call_operation(ctx, operation: activity, invoke_method: invoke_method)
99

1010
assert_pass_with_model(result, ctx, expected_model_attributes: expected_model_attributes, test: test, user_block: user_block, model_at: model_at, operation: activity)

lib/trailblazer/test/assertion/suite.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ def assert_pass(params_fragment, expected_attributes_to_merge, use_wtf=false, de
5050

5151
activity = kws[:operation] # FIXME.
5252
model_at = kws[:model_at] # FIXME.
53+
# invoke_method = kws[:invoke_method] if kws.key?(:invoke_method) # FIXME.
5354

54-
assertion.(activity, ctx, use_wtf: use_wtf, test: test, model_at: model_at, user_block: user_block, **expected_attributes)
55+
assertion.(activity, ctx, invoke_method: invoke_method, test: test, model_at: model_at, user_block: user_block, **expected_attributes)
5556
end
5657

5758
def assert_fail(params_fragment, expected_errors, use_wtf=false, assertion:, **kws)
5859
ctx, kws = normalize_for(params_fragment, use_wtf, **kws)
5960

6061
activity = kws[:operation] # FIXME.
62+
# invoke_method = kws[:invoke_method] # FIXME.
6163

6264
assertion.(activity, ctx, expected_errors, **kws)
6365
end
@@ -75,7 +77,7 @@ def ctx_for_params_fragment(params_fragment, key_in_params:, default_ctx:, **)
7577
# Gather all test case configuration. This involves reading all test `let` directives.
7678
def normalize_kws(use_wtf, user_block:, test:, operation: test.operation, expected_attributes: test.expected_attributes, contract_name: "default", model_at: :model, **options)
7779
kws = {
78-
user_block: user_block,
80+
# user_block: user_block,
7981
operation: operation,
8082
expected_attributes: expected_attributes,
8183
test: test,

test/assertion_test.rb

+22-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def validate(ctx, params:, **)
7373
include Trailblazer::Test::Assertion
7474
include Trailblazer::Test::Assertion::AssertExposes
7575
it "#assert_pass" do
76-
# assert_pass Create, {params: {title: 1}}, id: 1, invoke_method: :wtf?
76+
# FIXME: test that assert_* returns {ctx}
77+
# assert_pass Create, {params: {title: "Somewhere Far Beyond"}}, title: "Somewhere Far Beyond", invoke_method: :wtf?
7778

7879
test =
7980
Class.new(Test) do
@@ -117,13 +118,29 @@ def validate(ctx, params:, **)
117118
end
118119

119120
# test_0005_anonymous
121+
# We accept {:invoke_method} as a first level kw arg, currently.
120122
it do
121123
stdout, _ = capture_io do
122124
assert_pass Create, {params: {title: "Somewhere Far Beyond"}}, title: "Somewhere Far Beyond", invoke_method: :wtf?
123125
end
124126

125127
assert_equal stdout, %(`-- AssertionsTest::Create\n |-- \e[32mStart.default\e[0m\n |-- \e[32mmodel\e[0m\n `-- End.success\n)
126128
end
129+
130+
# test_0006_anonymous
131+
# We accept {:model_at} as a first level kw arg, currently.
132+
it do
133+
create = Class.new(Trailblazer::Operation) do
134+
step :model
135+
136+
def model(ctx, params:, **)
137+
ctx[:song] = Record.new(**params)
138+
end
139+
end
140+
141+
assert_pass create, {params: {title: "Somewhere Far Beyond"}}, title: "Somewhere Far Beyond", model_at: :song
142+
# assert_pass Create, {params: {title: "Somewhere Far Beyond"}}, {invoke_method: :wtf?, model_at: }, {...} # DISCUSS: this would be an alternative syntax.
143+
end
127144
end
128145

129146
test_1 = test.new(:test_0001_anonymous)
@@ -155,6 +172,10 @@ def validate(ctx, params:, **)
155172
test_5 = test.new(:test_0005_anonymous)
156173
failures = test_5.()
157174
assert_equal failures.size, 0
175+
176+
test_6 = test.new(:test_0006_anonymous)
177+
failures = test_6.()
178+
assert_equal failures.size, 0
158179
end
159180

160181
include Trailblazer::Test::Assertion

0 commit comments

Comments
 (0)