Skip to content

Commit

Permalink
feat(core): introduce MiddlewareCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 27, 2023
1 parent 5ca7868 commit d1b6ce8
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
require_relative "entities/caller"
require_relative "entities/chain"
require_relative "entities/container"
require_relative "entities/middleware_creator"
require_relative "entities/middleware"
require_relative "entities/stack"
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module ConvenientService
module Core
module Entities
class Config
module Entities
class MethodMiddlewares
module Entities
class MiddlewareCreator
##
# @!attribute [r] middleware
# @return [Class]
#
attr_reader :middleware

##
# @!attribute [r] arguments
# @return [ConvenientService::Support::Arguments]
#
attr_reader :arguments

##
# @param middleware [Class]
# @param arguments [ConvenientService::Support::Arguments]
# @return [void]
#
def initialize(middleware:, arguments:)
@middleware = middleware
@arguments = arguments
end

##
# @param other [Object]
# @return [Boolean, nil]
#
def ==(other)
return unless other.instance_of?(self.class)

return false if middleware != other.middleware
return false if arguments != other.arguments

true
end
end
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/NestedGroups
RSpec.describe ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::MiddlewareCreator do
include ConvenientService::RSpec::Matchers::DelegateTo

let(:middleware_creator) { described_class.new(middleware: middleware, arguments: arguments) }
let(:middleware) { Class.new(ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware) }
let(:arguments) { ConvenientService::Support::Arguments.new(:foo, foo: :bar) { :foo } }

example_group "attributes" do
include ConvenientService::RSpec::Matchers::HaveAttrReader

subject { middleware_creator }

it { is_expected.to have_attr_reader(:middleware) }
it { is_expected.to have_attr_reader(:arguments) }
end

example_group "instance methods" do
example_group "comparison" do
describe "#==" do
context "when `other` has different class" do
let(:other) { 42 }

it "returns `nil`" do
expect(middleware_creator == other).to be_nil
end
end

context "when `other` has different `middleware`" do
let(:other) { described_class.new(middleware: Class.new(ConvenientService::Core::Entities::Config::Entities::MethodMiddlewares::Entities::Middleware), arguments: arguments) }

it "returns `false`" do
expect(middleware_creator == other).to eq(false)
end
end

context "when `other` has different `arguments`" do
let(:other) { described_class.new(middleware: middleware, arguments: ConvenientService::Support::Arguments.null_arguments) }

it "returns `false`" do
expect(middleware_creator == other).to eq(false)
end
end

context "when `other` has same attributes" do
let(:other) { described_class.new(middleware: middleware, arguments: arguments) }

it "returns `true`" do
expect(middleware_creator == other).to eq(true)
end
end
end
end
end
end
# rubocop:enable RSpec/NestedGroups

0 comments on commit d1b6ce8

Please sign in to comment.