-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(has_negated_result): introduce #negated_result
- Loading branch information
Showing
15 changed files
with
182 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "has_negated_result/concern" | ||
require_relative "has_negated_result/exceptions" |
33 changes: 33 additions & 0 deletions
33
lib/convenient_service/service/plugins/has_negated_result/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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasNegatedResult | ||
module Concern | ||
include Support::Concern | ||
|
||
class_methods do | ||
## | ||
# @api public | ||
# @raise [ConvenientService::Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden] | ||
# | ||
def negated_result(...) | ||
new(...).negated_result | ||
end | ||
end | ||
|
||
instance_methods do | ||
## | ||
# @api public | ||
# @raise [ConvenientService::Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden] | ||
# | ||
def negated_result | ||
::ConvenientService.raise Exceptions::NegatedResultIsNotOverridden.new(service: self) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/convenient_service/service/plugins/has_negated_result/exceptions.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasNegatedResult | ||
module Exceptions | ||
class NegatedResultIsNotOverridden < ::ConvenientService::Exception | ||
def initialize_with_kwargs(service:) | ||
message = <<~TEXT | ||
Negated result method (#negated_result) of `#{service.class}` is NOT overridden. | ||
TEXT | ||
|
||
initialize(message) | ||
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
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
102 changes: 102 additions & 0 deletions
102
spec/lib/convenient_service/service/plugins/has_negated_result/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,102 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Service::Plugins::HasNegatedResult::Concern do | ||
include ConvenientService::RSpec::Helpers::IgnoringException | ||
|
||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
let(:service_class) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Minimal | ||
end | ||
end | ||
|
||
let(:service_instance) { service_class.new } | ||
let(:negated_result) { service_instance.negated_result } | ||
|
||
let(:args) { [:foo] } | ||
let(:kwargs) { {foo: :bar} } | ||
let(:block) { proc { :foo } } | ||
|
||
example_group "modules" do | ||
include ConvenientService::RSpec::Matchers::IncludeModule | ||
include ConvenientService::RSpec::PrimitiveMatchers::ExtendModule | ||
|
||
subject { described_class } | ||
|
||
it { is_expected.to include_module(ConvenientService::Support::Concern) } | ||
|
||
context "when included" do | ||
subject { service_class } | ||
|
||
let(:service_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) } | ||
it { is_expected.to extend_module(described_class::ClassMethods) } | ||
end | ||
end | ||
|
||
example_group "instance methods" do | ||
describe "#negated_result" do | ||
let(:exception_message) do | ||
<<~TEXT | ||
Negated result method (#negated_result) of `#{service_class}` is NOT overridden. | ||
TEXT | ||
end | ||
|
||
it "raises `ConvenientService::Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden`" do | ||
expect { negated_result } | ||
.to raise_error(ConvenientService::Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden) | ||
.with_message(exception_message) | ||
end | ||
|
||
specify do | ||
expect { ignoring_exception(ConvenientService::Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden) { negated_result } } | ||
.to delegate_to(ConvenientService, :raise) | ||
end | ||
end | ||
end | ||
|
||
example_group "class methods" do | ||
include ConvenientService::RSpec::Helpers::IgnoringException | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
let(:service_class) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Minimal | ||
|
||
def negated_result | ||
failure | ||
end | ||
end | ||
end | ||
|
||
describe ".negated_result" do | ||
specify do | ||
expect { service_class.negated_result(*args, **kwargs, &block) } | ||
.to delegate_to(service_class, :new) | ||
.with_arguments(*args, **kwargs, &block) | ||
end | ||
|
||
specify do | ||
allow(service_class).to receive(:new).and_return(service_instance) | ||
|
||
expect { service_class.negated_result(*args, **kwargs, &block) } | ||
.to delegate_to(service_instance, :negated_result) | ||
.and_return_its_value | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/MultipleMemoizedHelpers |
11 changes: 11 additions & 0 deletions
11
spec/lib/convenient_service/service/plugins/has_negated_result/exceptions_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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
RSpec.describe ConvenientService::Service::Plugins::HasNegatedResult::Exceptions do | ||
include ConvenientService::RSpec::PrimitiveMatchers::BeDescendantOf | ||
|
||
specify { expect(described_class::NegatedResultIsNotOverridden).to be_descendant_of(ConvenientService::Exception) } | ||
end |