-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support to use symbol instead block
- Loading branch information
Showing
7 changed files
with
74 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
module Zx | ||
module Core | ||
class Base | ||
attr_reader :ctx | ||
|
||
def initialize | ||
@success = true | ||
@type = :ok | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -661,11 +661,30 @@ def expected_error(err, type = nil) | |
expect { result.value! }.to raise_error(Zx::Result::FailureError) | ||
end | ||
|
||
describe 'process composition' do | ||
it 'Given process' do | ||
describe 'process using method blocks' do | ||
it 'returns a Given result' do | ||
input = { name: 'Thadeu Esteves', email: '[email protected]' } | ||
|
||
account = AccountCreation.deliver(input) | ||
account = AccountCreation.create_with_method_blocks(input) | ||
.on(:success, :user_created) { |user| p [:user_created, user] } | ||
.on(:success, :account_created) { |acc| p [:account_created, acc] } | ||
.on(:success, :mailer_subscribed) { |acc| p [:mailer_subscribed, acc] } | ||
.on(:success, :email_sent) { |acc| expect(acc.user.name).to eq('Thadeu Esteves') } | ||
.on(:failure, :user_not_created) { |error| p [:user_not_created, error] } | ||
.otherwise { |error| p [:otherwise, error] } | ||
|
||
expect(account.success?).to be_truthy | ||
expect(account.type).to eq(:email_sent) | ||
expect(account.unwrap.user.name).to eq('Thadeu Esteves') | ||
expect(account.unwrap.user.email).to eq('[email protected]') | ||
end | ||
end | ||
|
||
describe 'process methods symbols' do | ||
it 'returns a Given result' do | ||
input = { name: 'Thadeu Esteves', email: '[email protected]' } | ||
|
||
account = AccountCreation.create_with_method_symbols(input) | ||
.on(:success, :user_created) { |user| p [:user_created, user] } | ||
.on(:success, :account_created) { |acc| p [:account_created, acc] } | ||
.on(:success, :mailer_subscribed) { |acc| p [:mailer_subscribed, acc] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters