Skip to content

Commit

Permalink
feat(internals): add cache to class
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Feb 2, 2024
1 parent 084b0f4 commit b1363c7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ module HasCache
module Concern
include Support::Concern

class_methods do
##
# @return [ConvenientService::Support::Cache]
#
# @internal
# TODO: `Support::Cache.create(backend: :thread_safe_hash)`.
#
def cache
@cache ||= Support::Cache.create(backend: :hash)
end
end

instance_methods do
##
# @return [ConvenientService::Support::Cache]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
require "convenient_service"

RSpec.describe ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Plugins::HasCache::Concern do
let(:internals_class) do
Class.new.tap do |klass|
klass.class_exec(described_class) do |mod|
include mod
end
end
end

let(:internals_instance) { internals_class.new }

example_group "modules" do
include ConvenientService::RSpec::Matchers::IncludeModule

Expand All @@ -15,15 +25,45 @@
context "when included" do
subject { internals_class }

let(:internals_class) do
Class.new.tap do |klass|
klass.class_exec(described_class) do |mod|
include mod
end
end
it { is_expected.to include_module(described_class::InstanceMethods) }
end
end

example_group "class methods" do
include ConvenientService::RSpec::Matchers::DelegateTo
include ConvenientService::RSpec::PrimitiveMatchers::CacheItsValue

describe ".cache" do
specify do
expect { internals_class.cache }
.to delegate_to(ConvenientService::Support::Cache, :create)
.with_arguments(backend: :hash)
.and_return_its_value
end

it { is_expected.to include_module(described_class::InstanceMethods) }
specify do
expect { internals_class.cache }.to cache_its_value
end
end
end

example_group "instance methods" do
include ConvenientService::RSpec::Matchers::DelegateTo
include ConvenientService::RSpec::PrimitiveMatchers::CacheItsValue

describe "#cache" do
let(:internals) { internals_instance }

specify do
expect { internals.cache }
.to delegate_to(ConvenientService::Support::Cache, :create)
.with_arguments(backend: :hash)
.and_return_its_value
end

specify do
expect { internals.cache }.to cache_its_value
end
end
end
end

0 comments on commit b1363c7

Please sign in to comment.