Skip to content

Commit

Permalink
move/introduce Test.module!.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 28, 2025
1 parent 204c4ea commit f6dda5c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/trailblazer/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module Trailblazer
module Test
# Your code goes here...

def self.module!(*args, **options, &block)
Assertion.module!(*args, **options, &block)
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/activity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Test all assertions with a FastTrack class, not an Operation.
# TODO: This is currently not documented.
class AssertionActivityTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self, activity: true)
Trailblazer::Test.module!(self, activity: true)
Memo = Trailblazer::Test::Testing::Memo
VALID_INPUT = Memo::VALID_INPUT # {params: {memo: {title: "TODO", content: "Stock up beer"}}}
WTF_SUCCESS = %(AssertionActivityTest::Create
Expand Down Expand Up @@ -73,7 +73,7 @@ class Create < Trailblazer::Activity::FastTrack

# Test with the Assertion::Suite "DSL" module.
class SuiteWithActivityTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self, activity: true, suite: true)
Trailblazer::Test.module!(self, activity: true, suite: true)
Create = AssertionActivityTest::Create

let(:operation) { Create }
Expand Down Expand Up @@ -107,7 +107,7 @@ class EndpointWithActivityTest < Minitest::Spec
Create = AssertionActivityTest::Create
Memo = Trailblazer::Test::Testing::Memo

Trailblazer::Test::Assertion.module!(self, activity: true)
Trailblazer::Test.module!(self, activity: true)

def self.__(activity, options, **kws, &block) # TODO: move this to endpoint.
signal, (ctx, flow_options) = Trailblazer::Endpoint::Runtime.(
Expand Down
6 changes: 3 additions & 3 deletions test/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class AssertionsTest < Minitest::Spec
# UNCOMMENT for quick debugging.
# Trailblazer::Test::Assertion.module!(self)
# Trailblazer::Test.module!(self)
it "#assert_pass" do
# assert_pass? Create, {params: {title: "Somewhere Far Beyond"}}, title: "Somewhere Far Beyond"

test =
Class.new(Test) do
Trailblazer::Test::Assertion.module!(self)
Trailblazer::Test.module!(self)
Memo = Trailblazer::Test::Testing::Memo
Create = Memo::Operation::Create

Expand Down Expand Up @@ -172,7 +172,7 @@ def model(ctx, params:, **)

test =
Class.new(Test) do
Trailblazer::Test::Assertion.module!(self)
Trailblazer::Test.module!(self)
Memo = Trailblazer::Test::Testing::Memo
Create = Memo::Operation::Create
VALID_INPUT = Memo::VALID_INPUT # {params: {memo: {title: "TODO", content: "Stock up beer"}}}
Expand Down
4 changes: 2 additions & 2 deletions test/docs/assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Document {Assertion#asserr_pass} and friends.
class DocsAssertionTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self)
Trailblazer::Test.module!(self)

Memo = Trailblazer::Test::Testing::Memo

Expand Down Expand Up @@ -74,7 +74,7 @@ class DocsAssertionTest < Minitest::Spec
end

class ModelAtTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self)
Trailblazer::Test.module!(self)

module Memo
module Operation
Expand Down
2 changes: 1 addition & 1 deletion test/docs/mock_step_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class MockStepTest < Minitest::Spec
Trailblazer::Test::Assertion.module!(self)
Trailblazer::Test.module!(self)

Memo = Module.new

Expand Down
8 changes: 4 additions & 4 deletions test/docs/suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
# ...

class OperationSpec < Minitest::Spec
Trailblazer::Test::Assertion.module!(self, suite: true)
Trailblazer::Test.module!(self, suite: true)
end
#:operation-spec end

# {Memo}, {Memo::Operation::Create} etc is from lib/trailblazer/test/testing.rb.
class DocsSuiteAssertionsTest < Minitest::Spec
Memo = Trailblazer::Test::Testing::Memo
Trailblazer::Test::Assertion.module!(self, suite: true)
Trailblazer::Test.module!(self, suite: true)

Memo::Operation::Update = Class.new(Memo::Operation::Create)

#:test
#:install
class MemoOperationTest < Minitest::Spec # test/memo/operation_test.rb
#~zoom
Trailblazer::Test::Assertion.module!(self, suite: true)
Trailblazer::Test.module!(self, suite: true)
#:install end

# The default ctx passed into the tested operation.
Expand Down Expand Up @@ -275,7 +275,7 @@ class Create < Trailblazer::Operation
# Test that the Suite module also works with a Minitest::Test class.
#:test-suite
class MemoCreateTest < Minitest::Test
Trailblazer::Test::Assertion.module!(self, suite: true, spec: false)
Trailblazer::Test.module!(self, suite: true, spec: false)
#~skip
Memo = Trailblazer::Test::Testing::Memo
#~skip end
Expand Down
10 changes: 5 additions & 5 deletions test/suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Brutal unit tests for Suite.
class SuiteTest < Minitest::Spec
# UNCOMMENT for quick debugging.
# Trailblazer::Test::Assertion.module!(self, suite: true)
# Trailblazer::Test.module!(self, suite: true)
# let(:operation) { Trailblazer::Test::Testing::Memo::Operation::Create }
# let(:default_ctx) { {params: {memo: {title: "Note to self", content: "Remember me!"}}} }
# let(:expected_attributes) { {content: "Remember me!", persisted?: true} }
Expand All @@ -21,7 +21,7 @@ class SuiteTest < Minitest::Spec
# 2. Test result's arity by running assert_pass with a failing OP.
# 3. test different manual input vs different expected_attributes to see if all attributes are tested.

Trailblazer::Test::Assertion.module!(self, suite: true)
Trailblazer::Test.module!(self, suite: true)

let(:operation) { Memo::Operation::Create }
let(:default_ctx) { {params: {memo: {title: "Note to self", content: "Remember me!"}}} }
Expand Down Expand Up @@ -420,7 +420,7 @@ def model(ctx, params:, **)
# Test that the Suite module also works with a Minitest::Test class.
# DISCUSS: should we use the above test tactics and test this inside a test with {#assert_test_case_passes} etc?
class SuiteInNonSpecTest < Minitest::Test
Trailblazer::Test::Assertion.module!(self, suite: true, spec: false)
Trailblazer::Test.module!(self, suite: true, spec: false)

Memo = Trailblazer::Test::Testing::Memo

Expand All @@ -436,7 +436,7 @@ def test_our_assertions
end

# class AssertionActivityTest < Minitest::Spec
# Trailblazer::Test::Assertion.module!(self, activity: true)
# Trailblazer::Test.module!(self, activity: true)

# Record = Trailblazer::Test::Testing::Memo

Expand Down Expand Up @@ -468,7 +468,7 @@ def test_our_assertions

# # Test with the Assertion::Suite "DSL" module.
# class SuiteWithActivityTest < Minitest::Spec
# Trailblazer::Test::Assertion.module!(self, activity: true, suite: true)
# Trailblazer::Test.module!(self, activity: true, suite: true)
# # Record = AssertionsTest::Record
# # Create = AssertionActivityTest::Create

Expand Down

0 comments on commit f6dda5c

Please sign in to comment.