Skip to content

Commit

Permalink
make debugging work with all assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Dec 11, 2024
1 parent fe35e2a commit 57fce9d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
25 changes: 17 additions & 8 deletions lib/trailblazer/test/assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,38 @@ def self.actual(asserted, reader, name)

# Assertions for Activity, not for Operation.
module Activity

def self.invoke_activity(ctx, operation:, **)
signal, (ctx, _) = operation.call([ctx, {}]) # call with circuit interface. https://trailblazer.to/2.1/docs/operation/#operation-internals-circuit-interface

return signal, ctx
end

def self.invoke_activity_with_wtf(ctx, operation:, **)
def self.invoke_activity_with_tracing(ctx, operation:, **)
raise
end

module Assert
def assert_pass(*args, **options, &block)
super(*args, **options, invoke: Activity.method(:invoke_activity), &block)
def assert_pass(*args, invoke: Activity.method(:invoke_activity), **options, &block)
super(*args, **options, invoke: invoke, &block)
end

def assert_fail(*args, invoke: Activity.method(:invoke_activity), **options, &block)
super(*args, **options, invoke: invoke, &block)
end

# DISCUSS: only for Suite API so far.
def assert_pass?(*args, **options, &block)
assert_pass(*args, **options, invoke: Activity.method(:invoke_activity_with_tracing), &block)
end

def assert_fail(*args, **options, &block)
super(*args, **options, invoke: Activity.method(:invoke_activity), &block)
def assert_fail?(*args, **options, &block)
assert_fail(*args, **options, invoke: Activity.method(:invoke_activity_with_tracing), &block)
end
# TODO: test {#assert_fail?}
end

include Assertion # from Test::Assert, top-level
include Assert # our assert_* versions.
# include Assertion # from Test::Assert, top-level
# include Assert # our assert_* versions.
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/trailblazer/test/assertion/suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def Ctx(*args, **kws)
end

def assert_pass?(*args, **kws, &block)
assert_pass(*args, **kws, use_wtf: true, &block)
assert_pass(*args, **kws, invoke: Assertion::Wtf.method(:invoke_activity), &block)
end

def assert_fail?(*args, **kws, &block)
assert_fail(*args, **kws, use_wtf: true, &block)
assert_fail(*args, **kws, invoke: Assertion::Wtf.method(:invoke_activity), &block)
end

# Provide {Assert.assert_pass} which decouples the assertion logic from the actual test framework.
Expand Down Expand Up @@ -87,7 +87,8 @@ def normalize_kws(user_block:, test:, operation: test.operation, expected_attrib
contract_name: contract_name,
model_at: model_at,
user_block: user_block,
invoke: use_wtf ? Assertion::Wtf.method(:invoke_activity) : invoke,
# invoke: use_wtf ? Assertion::Wtf.method(:invoke_activity) : invoke,
invoke: invoke,

**normalize_kws_for_ctx(test: test, **options)
}
Expand Down
30 changes: 29 additions & 1 deletion test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,39 @@ def model(ctx, params:, **)
end
end

include Trailblazer::Test::Assertion::Activity
include Trailblazer::Test::Assertion
include Trailblazer::Test::Assertion::Activity::Assert
include Trailblazer::Test::Assertion::AssertExposes

it do
assert_pass Create, {params: {title: "Roxanne"}},
title: "Roxanne"
end
end

class AssertionActivitySuiteTest < Minitest::Spec
Record = AssertionsTest::Record

class Create < Trailblazer::Activity::FastTrack
step :validate
step :model

def validate(ctx, params:, **)
params[:title]
end

def model(ctx, params:, **)
ctx[:model] = Record.new(**params)
end
end

include Trailblazer::Test::Assertion::Suite
include Trailblazer::Test::Assertion::Activity::Assert
include Trailblazer::Test::Assertion::AssertExposes

let(:operation) { Create }

it do
assert_pass?({params: {title: "Roxanne"}}, {title: "Roxanne"})
end
end
File renamed without changes.

0 comments on commit 57fce9d

Please sign in to comment.