Skip to content

Commit

Permalink
refactor(inspect): add has_inspect placeholder for message
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed May 2, 2023
1 parent b5a9b7b commit eb8e1f6
Show file tree
Hide file tree
Showing 18 changed files with 282 additions and 23 deletions.
14 changes: 7 additions & 7 deletions lib/convenient_service/configs/awesome_print_inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class self::Data
replace Plugins::Data::HasInspect::Concern, Plugins::Data::HasAwesomePrintInspect::Concern
end
end
#
# class self::Message
# concerns do
# replace HasInspect::Concern, HasAwesomePrintInspect::Concern
# end
# end
#

class self::Message
concerns do
replace Plugins::Message::HasInspect::Concern, Plugins::Message::HasAwesomePrintInspect::Concern
end
end

# class self::Code
# concerns do
# replace HasInspect::Concern, HasAwesomePrintInspect::Concern
Expand Down
4 changes: 4 additions & 0 deletions lib/convenient_service/configs/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ class self::Data

class self::Message
include Core

concerns do
use Plugins::Message::HasInspect::Concern
end
end

class self::Code
Expand Down
1 change: 1 addition & 0 deletions lib/convenient_service/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def require_awesome_print_inspect
require_relative "service/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_awesome_print_inspect"
require_relative "service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect"
require_relative "configs/awesome_print_inspect"
require_relative "configs/awesome_print_inspect/aliases"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "message/commands"
require_relative "message/concern"
require_relative "message/plugins"

module ConvenientService
module Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require_relative "plugins/has_inspect"

require_relative "plugins/aliases"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module ConvenientService
module Plugins
Message = ::ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "has_awesome_print_inspect/concern"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

module ConvenientService
module Service
module Plugins
module HasResult
module Entities
class Result
module Plugins
module HasJSendStatusAndAttributes
module Entities
class Message
module Plugins
module HasAwesomePrintInspect
module Concern
include Support::Concern

instance_methods do
##
# @return [String]
#
def inspect
metadata = {
ConvenientService: {
entity: "Message",
result: result.class.name,
text: to_s
}
}

metadata.ai
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "has_inspect/concern"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module ConvenientService
module Service
module Plugins
module HasResult
module Entities
class Result
module Plugins
module HasJSendStatusAndAttributes
module Entities
class Message
module Plugins
module HasInspect
module Concern
include Support::Concern

instance_methods do
##
# @return [String]
#
def inspect
"<#{self.class} text: \"#{value}\">"
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
24 changes: 12 additions & 12 deletions spec/lib/convenient_service/configs/awesome_print_inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@
end
end

# example_group "service result message" do
# example_group "concerns" do
# it "removes `HasInspect::Concern` from service concerns" do
# expect(service_class::Result::Message.concerns.to_a).not_to include(HasInspect::Concern)
# end
#
# it "adds `HasAwesomeInspect::Concern` from service concerns" do
# expect(service_class::Result::Message.concerns.to_a).to include(HasAwesomeInspect::Concern)
# end
# end
# end
#
example_group "service result message" do
example_group "concerns" do
it "removes `ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern` from service concerns" do
expect(service_class::Result::Message.concerns.to_a).not_to include(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern)
end

it "adds `ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasAwesomePrintInspect::Concern` from service concerns" do
expect(service_class::Result::Message.concerns.to_a).to include(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasAwesomePrintInspect::Concern)
end
end
end

# example_group "service result code" do
# example_group "concerns" do
# it "removes `HasInspect::Concern` from service concerns" do
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/convenient_service/configs/minimal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@

example_group "service result message" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern
]
end

it "sets service result message concerns" do
expect(service_class::Result::Message.concerns.to_a).to eq(concerns)
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/convenient_service/configs/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@

example_group "service result message" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern
]
end

it "sets service result message concerns" do
expect(service_class::Result::Message.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@

example_group "service result message" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern
]
end

it "sets service result message concerns" do
expect(service_class::Result::Message.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@

example_group "service result message" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern
]
end

it "sets service result message concerns" do
expect(service_class::Result::Message.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/DescribeClass
RSpec.describe "convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/aliases" do
specify { expect(ConvenientService::Plugins::Message).to eq(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Message::Plugins) }
end
# rubocop:enable RSpec/DescribeClass
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasAwesomePrintInspect::Concern do
include ConvenientService::RSpec::Matchers::DelegateTo

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 { message_class }

let(:message_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
describe "#inspect" do
let(:service) do
Class.new do
include ConvenientService::Configs::Minimal

include ConvenientService::Configs::AwesomePrintInspect

def result
error(message: "foo")
end
end
end

let(:message) { service.result.message }

let(:keywords) { ["ConvenientService", "entity", "Message", "result", message.result.class.name, "text", "foo"] }

before do
##
# TODO: Remove when Core implements auto committing from `inspect`.
#
message.class.commit_config!
end

it "returns `inspect` representation of message" do
expect(message.inspect).to include(*keywords)
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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::HasJSendStatusAndAttributes::Entities::Message::Plugins::HasInspect::Concern do
include ConvenientService::RSpec::Matchers::DelegateTo

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 { message_class }

let(:message_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
describe "#inspect" do
let(:service) do
Class.new do
include ConvenientService::Configs::Minimal

def result
error(message: "foo")
end
end
end

let(:message) { service.result.message }

before do
##
# TODO: Remove when Core implements auto committing from `inspect`.
#
message.class.commit_config!
end

it "returns `inspect` representation of message" do
expect(message.inspect).to eq("<#{message.class} text: \"#{message}\">")
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers

0 comments on commit eb8e1f6

Please sign in to comment.