Skip to content

Commit

Permalink
test(core): add Concerns#include! specs
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Oct 30, 2022
1 parent 4abeb56 commit f855646
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def configure(&configuration_block)
#
# @see https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-require
#
# @internal
# NOTE: modification of instance variable is NOT thread-safe, that is why `Entities::DefaultConcern` is added.
# NOTE: `dup` is used for thread-safety as well.
#
def include!
return false if included?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def define!
# @return [Object]
#
# @internal
# NOTE: Stack is copied in order to be thread-safe.
# NOTE: Stack is copied in order to be thread-safe (`stack.dup`).
# NOTE: Stack backend will be rewritten in Core v3 in order to optimize performance of `stack.dup`.
# TODO: Measure before any rewrite.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

let(:klass) { service_class }

let(:default_concern) { ConvenientService::Core::Entities::Config::Entities::Concerns::Entities::DefaultConcern }

let(:concern) do
Module.new do
include ConvenientService::Support::Concern
Expand Down Expand Up @@ -648,9 +650,9 @@ def result
end
end

context "when default concern is included into `klass`" do
context "when default concern is included into `klass` (it is included by `include!`)" do
before do
concerns.include!
service_class.include default_concern
end

it "returns `true`" do
Expand Down Expand Up @@ -739,12 +741,71 @@ def foo(*args, **kwargs, &block)
end
end

##
# TODO: Specs.
#
# describe "#include!" do
# end
#
describe "#include!" do
context "when concerns are included" do
before do
concerns.include!
end

it "returns `false`" do
expect(concerns.include!).to eq(false)
end
end

context "when concerns are NOT included" do
context "when stack is NOT empty" do
context "when stack has one concern" do
before do
concerns.configure do |stack|
stack.use concern
end
end

it "calls default concern + that one concern" do
concerns.include!

expect(service_class.included_modules).to include(default_concern, concern)
end

it "returns `true`" do
expect(concerns.include!).to eq(true)
end
end

context "when stack has multiple concerns" do
before do
concerns.configure do |stack|
stack.use concern
stack.use other_concern
end
end

it "calls default concern + those multiple concerns" do
concerns.include!

expect(service_class.included_modules).to include(default_concern, concern, other_concern)
end

it "returns `true`" do
expect(concerns.include!).to eq(true)
end
end
end

context "when stack is empty" do
it "calls default concern" do
concerns.include!

expect(service_class.included_modules).to include(default_concern)
end

it "returns `true`" do
expect(concerns.include!).to eq(true)
end
end
end
end

describe "#to_a" do
context "when stack is NOT empty" do
it "returns concerns" do
Expand Down

0 comments on commit f855646

Please sign in to comment.