Skip to content

Commit

Permalink
make the user_block a kwarg as soon as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 6, 2024
1 parent 40d7c6a commit 73873b1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/trailblazer/test/assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module Assertion
# DISCUSS: move to Assertion::Minitest?
# Test case instance method. Specific to Minitest.
def assert_pass(activity, options, test: self, assertion: AssertPass, **kws, &block)
assertion.(activity, options, test: test, **kws, &block) # Forward {#assert_pass} to {AssertPass.call} or wherever your implementation sits.
assertion.(activity, options, test: test, user_block: block, **kws) # Forward {#assert_pass} to {AssertPass.call} or wherever your implementation sits.
end

# DISCUSS: move to Assertion::Minitest?
# Test case instance method. Specific to Minitest.
def assert_fail(activity, options, *args, test: self, assertion: AssertFail, **kws, &block)
assertion.(activity, options, *args, test: test, **kws, &block) # Forward {#assert_fail} to {AssertFail.call} or wherever your implementation sits.
assertion.(activity, options, *args, test: test, user_block: block, **kws) # Forward {#assert_fail} to {AssertFail.call} or wherever your implementation sits.
end

# Evaluate value if it's a lambda, and let the caller know whether we need an
Expand Down
4 changes: 2 additions & 2 deletions lib/trailblazer/test/assertion/assert_fail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module AssertFail
extend AssertPass::Utils

# {expected_errors} can be nil when using the {#assert_fail} block syntax.
def call(activity, ctx, expected_errors=nil, test:, **kws, &block)
def call(activity, ctx, expected_errors=nil, test:, **kws)
result, ctx, _ = call_operation(ctx, operation: activity) # FIXME: remove kws?

assert_fail_with_model(result, ctx, expected_errors: expected_errors, test: test, user_block: block, operation: activity)
assert_fail_with_model(result, ctx, expected_errors: expected_errors, test: test, operation: activity, **kws)
end

# @private
Expand Down
4 changes: 2 additions & 2 deletions lib/trailblazer/test/assertion/assert_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Assertion
module AssertPass
module_function

def call(activity, ctx, use_wtf: false, model_at: :model, test:, **expected_model_attributes, &block)
def call(activity, ctx, use_wtf: false, model_at: :model, test:, user_block:, **expected_model_attributes)
result, ctx, kws = call_operation(ctx, operation: activity)

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

def assert_pass_with_model(result, ctx, expected_model_attributes: {}, test:, **options)
Expand Down
22 changes: 11 additions & 11 deletions lib/trailblazer/test/assertion/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def self.included(includer)
end

def assert_pass(params_fragment, expected_attributes_to_merge, use_wtf=false, deep_merge: true, assertion: AssertPass, **kws, &block)
Assert.assert_pass(params_fragment, expected_attributes_to_merge, use_wtf, test: self, assertion: assertion, **kws, &block)
Assert.assert_pass(params_fragment, expected_attributes_to_merge, use_wtf, test: self, user_block: block, assertion: assertion, **kws)
end

def assert_fail(params_fragment, expected_errors, use_wtf=false, deep_merge: true, assertion: AssertFail, **kws, &block)
Assert.assert_fail(params_fragment, expected_errors, use_wtf, test: self, assertion: assertion, **kws, &block)
Assert.assert_fail(params_fragment, expected_errors, use_wtf, test: self, user_block: block, assertion: assertion, **kws)
end

def Ctx(*args, **kws)
Expand All @@ -35,27 +35,27 @@ def Ctx(*args, **kws)
module Assert
module_function

def normalize_for(params_fragment, use_wtf, block, **kws)
kws = normalize_kws(use_wtf, block, **kws)
def normalize_for(params_fragment, use_wtf, **kws)
kws = normalize_kws(use_wtf, **kws)
ctx = ctx_for_params_fragment(params_fragment, **kws)

return ctx, kws
end

#@public
def assert_pass(params_fragment, expected_attributes_to_merge, use_wtf=false, deep_merge: true, assertion:, test:, **kws, &block)
ctx, kws = normalize_for(params_fragment, use_wtf, block, test: test, **kws)
def assert_pass(params_fragment, expected_attributes_to_merge, use_wtf=false, deep_merge: true, assertion:, test:, user_block:, **kws)
ctx, kws = normalize_for(params_fragment, use_wtf, test: test, user_block: user_block, **kws)

expected_attributes = expected_attributes_for(expected_attributes_to_merge, **kws)

activity = kws[:operation] # FIXME.
model_at = kws[:model_at] # FIXME.

assertion.(activity, ctx, use_wtf: use_wtf, test: test, model_at: model_at, **expected_attributes, &block)
assertion.(activity, ctx, use_wtf: use_wtf, test: test, model_at: model_at, user_block: user_block, **expected_attributes)
end

def assert_fail(params_fragment, expected_errors, use_wtf=false, assertion:, **kws, &block)
ctx, kws = normalize_for(params_fragment, use_wtf, block, **kws)
def assert_fail(params_fragment, expected_errors, use_wtf=false, assertion:, **kws)
ctx, kws = normalize_for(params_fragment, use_wtf, **kws)

activity = kws[:operation] # FIXME.

Expand All @@ -73,9 +73,9 @@ def ctx_for_params_fragment(params_fragment, key_in_params:, default_ctx:, **)

# @private
# Gather all test case configuration. This involves reading all test `let` directives.
def normalize_kws(use_wtf, block, test:, operation: test.operation, expected_attributes: test.expected_attributes, contract_name: "default", model_at: :model, **options)
def normalize_kws(use_wtf, user_block:, test:, operation: test.operation, expected_attributes: test.expected_attributes, contract_name: "default", model_at: :model, **options)
kws = {
user_block: block,
user_block: user_block,
operation: operation,
expected_attributes: expected_attributes,
test: test,
Expand Down
2 changes: 1 addition & 1 deletion test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def validate(ctx, params:, **)

include Trailblazer::Test::Assertion
it "#assert_fail" do
# assert_fail Update, {params: {bla: 1}}, [:title]
assert_fail Update, {params: {bla: 1}}, [:title]
# assert_fail Update, {params: {bla: 1}} do |result|
# end

Expand Down
6 changes: 3 additions & 3 deletions test/docs/assertions/pass_fail_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def call
end

it do #5
assert_fail( {band: ""}, [:band] ) do |result|
assert_fail({band: ""}, [:band]) do |result|
assert_nil result[:model].title
@_m = result[:"contract.default"].errors.messages.inspect
end
Expand Down Expand Up @@ -539,8 +539,8 @@ class Overrider < Trailblazer::Operation
failures = test_5.()

assert_nil failures[0]
test_5.instance_variable_get(:@_m).must_equal %{{:band=>[\"must be filled\"]}}
assert_equal 4, test_5.instance_variable_get(:@assertions) # FIXME: why is this 4, not 3?
assert_equal test_5.instance_variable_get(:@_m), %({:band=>[\"must be filled\"]})
assert_equal 3, test_5.instance_variable_get(:@assertions)

# Can we override all let() options?
test_7 = test.new(:test_0007_anonymous)
Expand Down

0 comments on commit 73873b1

Please sign in to comment.