-
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.
feat(result): introduce Result#from_exception?
- Loading branch information
Showing
14 changed files
with
133 additions
and
5 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
3 changes: 3 additions & 0 deletions
3
...ervice/service/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception.rb
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "can_be_from_exception/concern" |
32 changes: 32 additions & 0 deletions
32
...ervice/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern.rb
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasJSendResult | ||
module Entities | ||
class Result | ||
module Plugins | ||
module CanBeFromException | ||
module Concern | ||
include Support::Concern | ||
|
||
instance_methods do | ||
## | ||
# @api public | ||
# | ||
# @return [Boolean] | ||
# | ||
def from_exception? | ||
Utils.to_bool(extra_kwargs[:from_exception]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
75 changes: 75 additions & 0 deletions
75
...e/plugins/has_j_send_result/entities/result/plugins/can_be_from_exception/concern_spec.rb
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeFromException::Concern, type: :standard do | ||
example_group "modules" do | ||
include ConvenientService::RSpec::Matchers::IncludeModule | ||
|
||
subject { described_class } | ||
|
||
it { is_expected.to include_module(ConvenientService::Support::Concern) } | ||
|
||
context "when included" do | ||
subject { result_class } | ||
|
||
let(:result_class) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
it { is_expected.to include_module(described_class::InstanceMethods) } | ||
end | ||
end | ||
|
||
example_group "instance methods" do | ||
include ConvenientService::RSpec::Helpers::StubService | ||
|
||
describe "#from_exception?" do | ||
let(:result) { service.result } | ||
|
||
let(:service) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Standard | ||
|
||
def result | ||
success | ||
end | ||
end | ||
end | ||
|
||
context "when result is NOT created by `stub_service`" do | ||
it "returns `false`" do | ||
expect(result.from_exception?).to eq(false) | ||
end | ||
end | ||
|
||
context "when result is created by `stub_service`" do | ||
let(:service) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Standard | ||
|
||
middlewares :result do | ||
use ConvenientService::Plugins::Service::RescuesResultUnhandledExceptions::Middleware | ||
end | ||
|
||
def result | ||
16 / 0 | ||
end | ||
end | ||
end | ||
|
||
it "returns `true`" do | ||
expect(result.from_exception?).to eq(true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
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