Skip to content

Commit

Permalink
extract PassWithAttributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 20, 2025
1 parent 2a8e50c commit 1019fef
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/trailblazer/test/assertion/assert_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def call(activity, ctx, invoke:, **options)
def assert_pass_with_model(signal, ctx, **options)
assert_after_call(ctx, **options) do |ctx|
Passed.new.call(signal, ctx, **options)
passed_with?(signal, ctx, **options)
PassedWithAttributes.new.call(signal, ctx, **options)
end
end

Expand Down Expand Up @@ -49,17 +49,23 @@ def assertion(expected_outcome, actual_outcome, error_msg, test:, **)
end

# @semi-public Used in rspec-trailblazer
# DISCUSS: should we default options like {:model_at} here?
def passed_with?(signal, ctx, model_at: :model, expected_model_attributes: {}, test:, **options)
actual_model = model_for(ctx, model_at: model_at)
class PassedWithAttributes
def call(signal, ctx, **options)
model = model_for(ctx, **options)

test.assert_exposes(actual_model, expected_model_attributes)
end
outcome, _ = assertion(ctx, **options, model: model)
outcome
end

def model_for(ctx, model_at:, **)
ctx[model_at]
end
# DISCUSS: should we default options like {:model_at} here?
def model_for(ctx, model_at: :model, **)
ctx[model_at]
end

def assertion(ctx, model:, expected_model_attributes:, test:, **)
test.assert_exposes(model, expected_model_attributes)
end
end

module Utils
# @private
Expand All @@ -70,8 +76,6 @@ def assert_after_call(ctx, user_block:, **kws)

ctx
end


end # Utils

module Errors
Expand Down

0 comments on commit 1019fef

Please sign in to comment.