Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace .must_equal with assert_equal #50

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/docs/autogenerated/operation_each_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def notify_composers(ctx, index:, composer:, **)

it "{item_key: :composer}" do
E::Mailer.send_options = []

assert_invoke E::Song::Operation::Cover, params: {id: 1},
expected_ctx_variables: {
model: B::Song.find_by(id: 1),
Expand Down Expand Up @@ -287,6 +288,7 @@ def composers_for_each(ctx, model:, **)

it "Each(Activity::Railway)" do
D::Mailer.send_options = []

assert_invoke D::Song::Operation::Cover, params: {id: 1},
seq: "[:rearrange]",
expected_ctx_variables: {
Expand Down
5 changes: 4 additions & 1 deletion test/docs/autogenerated/operation_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Update < Trailblazer::Operation
it do
#:key-title-fail
result = Song::Operation::Update.(params: {title: nil}, seq: [])

assert_equal result[:model].inspect, %{nil}
#:key-title-fail end
end
Expand Down Expand Up @@ -204,6 +205,7 @@ class Create < Trailblazer::Operation

it do
result = Song::Operation::Create.(params: {}, :"model.class" => Hit, seq: [])

assert_equal result[:model].inspect, %{#<struct #{Hit} id=nil, title=nil>}
end
end
Expand All @@ -224,15 +226,16 @@ class Create < Trailblazer::Operation
#:in end

result = Song::Operation::Create.(params: {}, my_id: 1, :"model.class" => Hit)

assert_equal result[:model].inspect, %{#<struct #{Hit} id=1, title=nil>}
=begin
#:in-call
result = Create.(my_id: 1)
#:in-call end
=end
end
end
end
end

class Model404TerminusTest < Minitest::Spec
Song = Class.new(DocsModelTest::Song)
Expand Down
5 changes: 5 additions & 0 deletions test/docs/each_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def notify_composers(ctx, index:, composer:, **)

it "{item_key: :composer}" do
E::Mailer.send_options = []

assert_invoke E::Song::Activity::Cover, params: {id: 1},
expected_ctx_variables: {
model: B::Song.find_by(id: 1),
Expand Down Expand Up @@ -288,6 +289,7 @@ def composers_for_each(ctx, model:, **)

it "Each(Activity::Railway)" do
D::Mailer.send_options = []

assert_invoke D::Song::Activity::Cover, params: {id: 1},
seq: "[:rearrange]",
expected_ctx_variables: {
Expand Down Expand Up @@ -789,6 +791,7 @@ def self.block

# signal, (_ctx, _) = Trailblazer::Activity::TaskWrap.invoke(activity, [ctx])
signal, (_ctx, _) = Trailblazer::Developer.wtf?(activity, [ctx], exec_context: my_exec_context)

assert_equal _ctx[:collected_from_each], ["1-0", "2-1", "3-2"]
end

Expand Down Expand Up @@ -826,6 +829,7 @@ def compute_item_with_current_user(ctx, item:, index:, current_user:, **)
},
{}]
)

assert_invoke activity, dataset: ["one", "two", "three"], current_user: Object, expected_ctx_variables: {collected_from_each: ["one-0-Object", "two-1-Object", "three-2-Object"]}
end

Expand Down Expand Up @@ -901,6 +905,7 @@ def check(ctx, item:, **)

#@ fail at 3 but still collect 3rd iteration!
Trailblazer::Developer.wtf?(activity, [{dataset: [1,2,3]}, {}])

assert_invoke activity, dataset: [1,2,3],
expected_ctx_variables: {collected_from_each: ["1", "2", "3"]},
seq: "[]",
Expand Down
28 changes: 15 additions & 13 deletions test/docs/guard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ def process(options, **)
#:proc end

it { Create.(pass: false)[:x].must_be_nil }
it { Create.(pass: true)[:x].must_equal true }

it { assert_equal Create.(pass: true)[:x], true }

#- result object, guard
it { Create.(pass: true)[:"result.policy.default"].success?.must_equal true }
it { Create.(pass: false)[:"result.policy.default"].success?.must_equal false }
it { assert_equal Create.(pass: true)[:"result.policy.default"].success?, true }
it { assert_equal Create.(pass: false)[:"result.policy.default"].success?, false }

#---
#- Guard inheritance
class New < Create
step Policy::Guard( ->(options, current_user:, **) { current_user } ), override: true
end

it { Trailblazer::Developer.railway(New).must_equal %{[>policy.default.eval,>process]} }
it { assert_equal Trailblazer::Developer.railway(New), %{[>policy.default.eval,>process]} }
end

#---
Expand Down Expand Up @@ -59,7 +60,8 @@ def process(options, **)
#:callable-op end

it { Create.(pass: false)[:x].must_be_nil }
it { Create.(pass: true)[:x].must_equal true }

it { assert_equal Create.(pass: true)[:x], true }
end

#---
Expand All @@ -83,8 +85,8 @@ def process(options, **)
end
#:method end

it { Create.(pass: false).inspect(:x).must_equal %{<Result:false [nil] >} }
it { Create.(pass: true).inspect(:x).must_equal %{<Result:true [true] >} }
it { assert_equal Create.(pass: false).inspect(:x), %{<Result:false [nil] >} }
it { assert_equal Create.(pass: true).inspect(:x), %{<Result:true [true] >} }
end

#---
Expand All @@ -97,8 +99,8 @@ class Create < Trailblazer::Operation
end
#:name end

it { Create.(:current_user => nil )[:"result.policy.user"].success?.must_equal false }
it { Create.(:current_user => Module)[:"result.policy.user"].success?.must_equal true }
it { assert_equal Create.(:current_user => nil )[:"result.policy.user"].success?, false }
it { assert_equal Create.(:current_user => Module)[:"result.policy.user"].success?, true }

it {
#:name-result
Expand All @@ -117,7 +119,7 @@ class Create < Trailblazer::Operation
end
#:di-op end

it { Create.(:current_user => Module).inspect("").must_equal %{<Result:true [nil] >} }
it { assert_equal Create.(:current_user => Module).inspect(""), %{<Result:true [nil] >} }
it {
result =
#:di-call
Expand All @@ -126,7 +128,7 @@ class Create < Trailblazer::Operation
:"policy.default.eval" => Trailblazer::Operation::Policy::Guard.build(->(options, **) { false })
)
#:di-call end
result.inspect("").must_equal %{<Result:false [nil] >} }
assert_equal result.inspect(""), %{<Result:false [nil] >} }
end

#---
Expand All @@ -137,7 +139,7 @@ class Create < Trailblazer::Operation
end

it { assert_raises(ArgumentError) { Create.() } }
it { Create.(:current_user => Module).success?.must_equal true }
it { assert_equal Create.(:current_user => Module).success?, true }
end

#---
Expand All @@ -151,7 +153,7 @@ class Create < Trailblazer::Operation
end
#:before end

it { Trailblazer::Developer.railway(Create).must_equal %{[>policy.default.eval,>model!]} }
it { assert_equal Trailblazer::Developer.railway(Create), %{[>policy.default.eval,>model!]} }
it do
#:before-pipe
Trailblazer::Developer.railway(Create, style: :rows) #=>
Expand Down
2 changes: 1 addition & 1 deletion test/docs/macro_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Create < Trailblazer::Operation
end
=end

it { Trailblazer::Developer.railway(Create).must_equal %{[>my_policy.manager]} }
it { assert_equal Trailblazer::Developer.railway(Create), %{[>my_policy.manager]} }
end


Expand Down
3 changes: 3 additions & 0 deletions test/docs/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Update < Trailblazer::Activity::Railway
it do
#:key-title-fail
signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Update, params: {title: nil}, seq: [])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding newlines between #: blocks you're changing the way documentation is rendered, so be careful with that! 👶

assert_equal ctx[:model].inspect, %{nil}
#:key-title-fail end
end
Expand Down Expand Up @@ -203,6 +204,7 @@ class Create < Trailblazer::Activity::Railway

it do
signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Create, params: {}, :"model.class" => Hit, seq: [])

assert_equal ctx[:model].inspect, %{#<struct #{Hit} id=nil, title=nil>}
end
end
Expand All @@ -223,6 +225,7 @@ class Create < Trailblazer::Operation
#:in end

signal, (ctx, _) = Trailblazer::Activity.(Song::Activity::Create, params: {}, my_id: 1, :"model.class" => Hit)

assert_equal ctx[:model].inspect, %{#<struct #{Hit} id=1, title=nil>}
=begin
#:in-call
Expand Down
2 changes: 2 additions & 0 deletions test/docs/nested_static_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,11 @@ class NestedStrategyComplianceTest < Minitest::Spec
Trailblazer::Developer.wtf?(Song::Activity::Create, [{params: {type: "vorbis"}, seq: []}])

output, _ = trace Song::Activity::Create, params: {type: "vorbis"}, seq: []

assert_equal output, trace.split("\n")[2..-2].join("\n").sub("Song::Activity::Create", "TOP")

output, _ = trace Song::Activity::Create, params: {type: "mp3"}, seq: []

assert_equal output, %{TOP
|-- Start.default
|-- model
Expand Down
36 changes: 18 additions & 18 deletions test/docs/pundit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class Create < Trailblazer::Operation
end
#:pundit end

it { Trailblazer::Developer.railway(Create).must_equal %{[>model.build,>policy.default.eval]} }
it { Create.(params: {}, current_user: Module).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { Create.(params: {} ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { assert_equal Trailblazer::Developer.railway(Create), %{[>model.build,>policy.default.eval]} }
it { assert_equal Create.(params: {}, current_user: Module).inspect(:model), %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { assert_equal Create.(params: {}).inspect(:model), %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
seuros marked this conversation as resolved.
Show resolved Hide resolved

it do
#:pundit-result
result = Create.(params: {}, current_user: Module)
result[:"result.policy.default"].success? #=> true
result[:"result.policy.default"][:policy] #=> #<MyPolicy ...>
result = Create.(params: {}, current_user: Module)
result[:"result.policy.default"].success? #=> true
result[:"result.policy.default"][:policy] #=> #<MyPolicy ...>
#:pundit-result end
result[:"result.policy.default"].success?.must_equal true
result[:"result.policy.default"][:policy].is_a?(MyPolicy).must_equal true
assert_equal result[:"result.policy.default"].success?, true
assert_equal result[:"result.policy.default"][:policy].is_a?(MyPolicy), true
end

#---
Expand All @@ -49,9 +49,9 @@ class New < Create
step Policy::Pundit( MyPolicy, :new? ), override: true
end

it { Trailblazer::Developer.railway(New).must_equal %{[>model.build,>policy.default.eval]} }
it { New.(params: {}, current_user: Class ).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { New.(params: {}, current_user: nil ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { assert_equal Trailblazer::Developer.railway(New), %{[>model.build,>policy.default.eval]} }
it { assert_equal New.(params: {}, current_user: Class ).inspect(:model), %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
it { assert_equal New.(params: {}, current_user: nil ).inspect(:model), %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }

#---
#- override with :name
Expand All @@ -64,10 +64,10 @@ class Update < Edit
step Policy::Pundit( MyPolicy, :new?, name: "first" ), override: true
end

it { Trailblazer::Developer.railway(Edit).must_equal %{[>policy.first.eval,>policy.second.eval]} }
it { Edit.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:false [nil] >} }
it { Trailblazer::Developer.railway(Update).must_equal %{[>policy.first.eval,>policy.second.eval]} }
it { Update.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:true [nil] >} }
it { assert_equal Trailblazer::Developer.railway(Edit), %{[>policy.first.eval,>policy.second.eval]} }
it { assert_equal Edit.(params: {}, current_user: Class).inspect(:model), %{<Result:false [nil] >} }
it { assert_equal Trailblazer::Developer.railway(Update), %{[>policy.first.eval,>policy.second.eval]} }
it { assert_equal Update.(params: {}, current_user: Class).inspect(:model), %{<Result:true [nil] >} }

#---
# dependency injection
Expand All @@ -85,7 +85,7 @@ def create?
:"policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
)
#:di-call end
result.inspect("").must_equal %{<Result:true [nil] >} }
assert_equal result.inspect(""), %{<Result:true [nil] >} }
end

#-
Expand All @@ -106,7 +106,7 @@ class Create < Trailblazer::Operation
result = Create.(params: {}, current_user: Module)
result[:"result.policy.after_model"].success? #=> true
#:name-call end
result[:"result.policy.after_model"].success?.must_equal true }
assert_equal result[:"result.policy.after_model"].success?, true }
end

#---
Expand All @@ -123,7 +123,7 @@ class Create < Trailblazer::Operation
# #:class-level end

# it { Create.(); Create["result.policy"].must_be_nil }
# it { Create.(params: {}, current_user: Module)["x"].must_equal true }
# it { Create.(params: {}, current_user: Module)["x"], true }
# it { Create.(params: {} )["x"].must_be_nil }
# end

Expand Down
25 changes: 13 additions & 12 deletions test/docs/rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ class NestedInsanity < Trailblazer::Operation
fail ->(options, **) { options["outer-err"] = true }, id: "nested/failure"
end

it { Trailblazer::Developer.railway(NestedInsanity).must_match /\[>Rescue\/.{1,3},>nested/ } # FIXME: better introspect tests for all id-generating macros.
it { NestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
it { NestedInsanity.( "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
it { NestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
it { assert_match /\[>Rescue\/.{1,3},>nested/, Trailblazer::Developer.railway(NestedInsanity) } # FIXME: better introspect tests for all id-generating macros.
it { assert_equal NestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
it { assert_equal NestedInsanity.( "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
it { assert_equal NestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }

#-
# inheritance
class UbernestedInsanity < NestedInsanity
end

it { UbernestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
it { UbernestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
it { assert_equal UbernestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
it { assert_equal UbernestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
end

class RescueTest < Minitest::Spec
Expand Down Expand Up @@ -130,8 +130,8 @@ class Memo::Create < Trailblazer::Operation
include Rehash
end

it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class), %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class), %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
end

=begin
Expand Down Expand Up @@ -160,8 +160,8 @@ def my_handler(exception, (ctx), *)
end
#:rescue-method end

it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class), %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class), %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
end

=begin
Expand All @@ -185,8 +185,8 @@ class Memo::Create < Trailblazer::Operation
include T.def_steps(:find_model, :update, :notify, :log_error, :rehash)
end

it { Memo::Create.( { seq: [], } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update]] >} }
it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq), %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
it { assert_equal Memo::Create.( { seq: [], update: false } ).inspect(:seq), %{<Result:false [[:find_model, :update]] >} }
end

class RescueIDTest < Minitest::Spec
Expand Down Expand Up @@ -239,6 +239,7 @@ def validate(ctx, validate: false, seq:, **)
ctx = {validate: false}

output, _ = trace activity, ctx

assert_equal output, %(TOP
|-- Start.default
|-- Rescue/1
Expand Down
Loading
Loading