-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service): introduce ConvenientService::Service::Plugins::CanHave…
…Steps.step?
- Loading branch information
Showing
5 changed files
with
155 additions
and
0 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
1 change: 1 addition & 0 deletions
1
lib/convenient_service/service/plugins/can_have_steps/commands.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "commands/create_step_class" | ||
require_relative "commands/is_step" |
34 changes: 34 additions & 0 deletions
34
lib/convenient_service/service/plugins/can_have_steps/commands/is_step.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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConvenientService | ||
module Service | ||
module Plugins | ||
module CanHaveSteps | ||
module Commands | ||
class IsStep < Support::Command | ||
## | ||
# @!attribute [r] step | ||
# @return [Object] Can be any type. | ||
# | ||
attr_reader :step | ||
|
||
## | ||
# @param step [Object] Can be any type. | ||
# @return [void] | ||
# | ||
def initialize(step:) | ||
@step = step | ||
end | ||
|
||
## | ||
# @return [Boolean] | ||
# | ||
def call | ||
step.class.include?(Entities::Step::Concern) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
spec/lib/convenient_service/service/plugins/can_have_steps/commands/is_step_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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups | ||
RSpec.describe ConvenientService::Service::Plugins::CanHaveSteps::Commands::IsStep, type: :standard do | ||
example_group "class methods" do | ||
describe ".call" do | ||
let(:command_result) { described_class.call(step: step) } | ||
|
||
context "when `step` class does NOT include `ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step::Concern`" do | ||
let(:step) { 42 } | ||
|
||
it "returns `false`" do | ||
expect(command_result).to eq(false) | ||
end | ||
end | ||
|
||
context "when `step` class includes `ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step::Concern`" do | ||
let(:service) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Essential | ||
|
||
step :result | ||
|
||
def result | ||
success | ||
end | ||
end | ||
end | ||
|
||
let(:step) { service.new.steps.first } | ||
|
||
it "returns `true`" do | ||
expect(command_result).to eq(true) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups |
36 changes: 36 additions & 0 deletions
36
spec/lib/convenient_service/service/plugins/can_have_steps_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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/NestedGroups | ||
RSpec.describe ConvenientService::Service::Plugins::CanHaveSteps, type: :standard do | ||
include ConvenientService::RSpec::Matchers::DelegateTo | ||
|
||
example_group "class methods" do | ||
describe ".step?" do | ||
let(:service) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Essential | ||
|
||
step :result | ||
|
||
def result | ||
success | ||
end | ||
end | ||
end | ||
|
||
let(:step) { service.new.steps.first } | ||
|
||
specify do | ||
expect { described_class.step?(step) } | ||
.to delegate_to(ConvenientService::Service::Plugins::CanHaveSteps::Commands::IsStep, :call) | ||
.with_arguments(step: step) | ||
.and_return_its_value | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/NestedGroups |