-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactor mock_step
and deprecate subprocess
kwarg
#25
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
require "test_helper" | ||
|
||
class DocsMockingTest < MiniTest::Spec | ||
class DocsMockingTest < Minitest::Spec | ||
include Trailblazer::Test::Assertions | ||
include Trailblazer::Test::Operation::Assertions | ||
include Trailblazer::Test::Operation::Helper | ||
|
||
User = Struct.new(:name) | ||
|
||
#:mock-show-operation | ||
class Show < Trailblazer::Activity::FastTrack | ||
class Complexity < Trailblazer::Activity::FastTrack | ||
class ExternalApi < Trailblazer::Activity::FastTrack | ||
class Show < Trailblazer::Operation | ||
class Complexity < Trailblazer::Operation | ||
class ExternalApi < Trailblazer::Operation | ||
step :make_call | ||
#~method | ||
include Testing.def_steps(:make_call) | ||
|
@@ -26,19 +32,18 @@ class ExternalApi < Trailblazer::Activity::FastTrack | |
end | ||
#:mock-show-operation end | ||
|
||
include Trailblazer::Test::Operation::Helper | ||
|
||
describe "#mock_step" do | ||
let(:default_params) { { seq: [] } } | ||
let(:operation) { Show } | ||
let(:default_ctx) { { seq: [] } } | ||
let(:expected_attrs) { {} } | ||
|
||
#:simple-mock-step | ||
it "mocks loading user" do | ||
new_activity = mock_step(Show, id: :load_user) do |ctx| | ||
ctx[:user] = Struct.new(:name).new('Mocky') | ||
ctx[:user] = User.new('Mocky') | ||
end | ||
|
||
assert_pass new_activity, default_params, {} do |(signal, (ctx, flow_options))| | ||
assert_pass({}, {}, operation: new_activity) do |ctx| | ||
assert_equal ctx[:user].name, 'Mocky' | ||
|
||
#~method | ||
|
@@ -56,39 +61,56 @@ class ExternalApi < Trailblazer::Activity::FastTrack | |
#:mock-subprocess end | ||
|
||
#~method | ||
assert_pass new_activity, default_params, {} do |(signal, (ctx, flow_options))| | ||
assert_pass({}, {}, operation: new_activity) do |ctx| | ||
assert_equal ctx[:seq], [:load_user] | ||
end | ||
#~method end | ||
end | ||
|
||
it "mocks subprocess step" do | ||
#:mock-subprocess-step | ||
new_activity = mock_step(Show, id: :some_complex_task, subprocess: Show::Complexity) do | ||
new_activity = mock_step(Show, id: :some_complex_task, subprocess_path: [Show::Complexity]) do | ||
# Mock only single step from nested activity to do nothing | ||
true | ||
end | ||
#:mock-subprocess-step end | ||
|
||
#~method | ||
assert_pass new_activity, default_params, {} do |(signal, (ctx, flow_options))| | ||
assert_pass({}, {}, operation: new_activity) do |ctx| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I want to compare |
||
assert_equal ctx[:seq], [:load_user, :make_call] | ||
end | ||
#~method end | ||
end | ||
|
||
it "mocks nested subprocess step" do | ||
#:mock-nested-subprocess-step | ||
new_activity = mock_step(Show, id: :make_call, subprocess: Show::Complexity, subprocess_path: [Show::Complexity::ExternalApi]) do | ||
new_activity = mock_step(Show, id: :make_call, subprocess_path: [Show::Complexity, Show::Complexity::ExternalApi]) do | ||
# Some JSON response | ||
{ name: 'Mocky' } | ||
end | ||
#:mock-nested-subprocess-step end | ||
|
||
#~method | ||
assert_pass new_activity, default_params, {} do |(signal, (ctx, flow_options))| | ||
assert_pass({}, {}, operation: new_activity) do |ctx| | ||
assert_equal ctx[:seq], [:load_user, :some_complex_task] | ||
end | ||
#~method end | ||
end | ||
|
||
it "shows warning for deprecated `subprocess`" do | ||
#~method | ||
_, warning = capture_io do | ||
new_activity = mock_step(Show, id: :make_call, subprocess: Show::Complexity, subprocess_path: [Show::Complexity::ExternalApi]) do | ||
{ name: 'Mocky' } | ||
end | ||
|
||
assert_pass({}, {}, operation: new_activity) do |ctx| | ||
assert_equal ctx[:seq], [:load_user, :some_complex_task] | ||
end | ||
end | ||
|
||
assert_match ":subprocess is deprecated and will be removed in 1.0.0. Pass `subprocess_path: #{[Show::Complexity, Show::Complexity::ExternalApi]}` instead.", warning | ||
#~method end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we name it
:path
instead of:subprocess_path
(feels clumsy)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah, but I thought
path
resonates more withActivity::Path
and we allowRailway
andFastTrack
too 😄Having
subprocess
in it makes intent clear, how about justsubprocess
orsubprocesses
?