-
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(has_inspect): indroduce inspect for Service and Result
- Loading branch information
Showing
14 changed files
with
260 additions
and
48 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "has_inspect/concern" |
22 changes: 22 additions & 0 deletions
22
lib/convenient_service/service/plugins/has_inspect/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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasInspect | ||
module Concern | ||
include Support::Concern | ||
|
||
instance_methods do | ||
## | ||
# @return [String] | ||
# | ||
def inspect | ||
"<#{self.class.name}>" | ||
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
3 changes: 3 additions & 0 deletions
3
lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect.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 "has_inspect/concern" |
30 changes: 30 additions & 0 deletions
30
...venient_service/service/plugins/has_result/entities/result/plugins/has_inspect/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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module HasResult | ||
module Entities | ||
class Result | ||
module Plugins | ||
module HasInspect | ||
module Concern | ||
include Support::Concern | ||
|
||
instance_methods do | ||
## | ||
# @return [String] | ||
# | ||
def inspect | ||
"<#{service.class.name}::Result status: :#{status}>" | ||
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
47 changes: 47 additions & 0 deletions
47
spec/lib/convenient_service/service/plugins/has_inspect/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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Service::Plugins::HasInspect::Concern do | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
let(:service_class) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
|
||
def self.name | ||
"Service" | ||
end | ||
end | ||
end | ||
end | ||
|
||
let(:service_instance) { service_class.new } | ||
|
||
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 { service_class } | ||
|
||
it { is_expected.to include_module(described_class::InstanceMethods) } | ||
end | ||
end | ||
|
||
example_group "instance methods" do | ||
describe "#inspect" do | ||
it "returns `inspect` representation of service" do | ||
expect(service_instance.inspect).to eq("<#{service_class.name}>") | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
3 changes: 3 additions & 0 deletions
3
spec/lib/convenient_service/service/plugins/has_inspect_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,3 @@ | ||
## | ||
# TODO: Integration specs. | ||
# |
94 changes: 94 additions & 0 deletions
94
...nt_service/service/plugins/has_result/entities/result/plugins/has_inspect/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,94 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasInspect::Concern do | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
example_group "modules" do | ||
include ConvenientService::RSpec::Matchers::IncludeModule | ||
|
||
subject { described_class } | ||
|
||
let(:result_class) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:result_instance) { result_class.new } | ||
|
||
it { is_expected.to include_module(ConvenientService::Support::Concern) } | ||
|
||
context "when included" do | ||
subject { result_class } | ||
|
||
before { result_class } | ||
|
||
it { is_expected.to include_module(described_class::InstanceMethods) } | ||
end | ||
end | ||
|
||
example_group "instance methods" do | ||
let(:service_class) do | ||
Class.new do | ||
def self.name | ||
"Service" | ||
end | ||
end | ||
end | ||
|
||
let(:service_instance) { service_class.new } | ||
|
||
# rubocop:disable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock | ||
let(:result_class) do | ||
Class.new do | ||
include ConvenientService::Core | ||
|
||
concerns do | ||
use ConvenientService::Common::Plugins::HasInternals::Concern | ||
use ConvenientService::Common::Plugins::HasConstructor::Concern | ||
use ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Concern | ||
use ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasInspect::Concern | ||
end | ||
|
||
middlewares :initialize do | ||
use ConvenientService::Common::Plugins::NormalizesEnv::Middleware | ||
|
||
use ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJsendStatusAndAttributes::Middleware | ||
end | ||
|
||
class self::Internals | ||
include ConvenientService::Core | ||
|
||
concerns do | ||
use ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins::HasCache::Concern | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock | ||
|
||
let(:result_instance) do | ||
result_class.new( | ||
status: :success, | ||
data: {}, | ||
message: "", | ||
code: :default_success, | ||
service: service_instance | ||
) | ||
end | ||
|
||
describe "#inspect" do | ||
it "returns `inspect` representation of result" do | ||
expect(result_instance.inspect).to eq("<#{result_instance.service.class.name}::Result status: :#{result_instance.status}>") | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
3 changes: 3 additions & 0 deletions
3
...convenient_service/service/plugins/has_result/entities/result/plugins/has_inspect_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,3 @@ | ||
## | ||
# TODO: Integration specs. | ||
# |
Oops, something went wrong.