-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(rspec): add direct specs to modules
- Loading branch information
Showing
22 changed files
with
435 additions
and
188 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
spec/lib/convenient_service/rspec/helpers/ignoring_exception_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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
RSpec.describe ConvenientService::RSpec::Helpers::IgnoringException do | ||
include ConvenientService::RSpec::PrimitiveMatchers::DelegateTo | ||
|
||
example_group "instance methods" do | ||
describe "#ignoring_exception" do | ||
let(:klass) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:instance) { klass.new } | ||
|
||
let(:exception) { ArgumentError } | ||
let(:block) { proc { raise exception } } | ||
|
||
specify do | ||
expect { instance.ignoring_exception(exception, &block) } | ||
.to delegate_to(ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException, :new) | ||
.with_arguments(exception, &block) | ||
end | ||
end | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
spec/lib/convenient_service/rspec/helpers/stub_service_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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
RSpec.describe ConvenientService::RSpec::Helpers::StubService do | ||
include ConvenientService::RSpec::PrimitiveMatchers::DelegateTo | ||
|
||
example_group "instance methods" do | ||
let(:klass) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:instance) { klass.new } | ||
|
||
describe "#stub_service" do | ||
let(:service_class) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Standard | ||
end | ||
end | ||
|
||
specify do | ||
expect { instance.stub_service(service_class) } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::StubService, :new) | ||
.with_arguments(service_class) | ||
end | ||
end | ||
|
||
describe "#return_result" do | ||
let(:status) { :success } | ||
|
||
specify do | ||
expect { instance.return_result(status) } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::StubService::Entities::ResultSpec, :new) | ||
.with_arguments(status: status) | ||
end | ||
end | ||
|
||
describe "#return_success" do | ||
specify do | ||
expect { instance.return_success } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::StubService::Entities::ResultSpec, :new) | ||
.with_arguments(status: :success) | ||
end | ||
end | ||
|
||
describe "#return_failure" do | ||
specify do | ||
expect { instance.return_failure } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::StubService::Entities::ResultSpec, :new) | ||
.with_arguments(status: :failure) | ||
end | ||
end | ||
|
||
describe "#return_error" do | ||
specify do | ||
expect { instance.return_error } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::StubService::Entities::ResultSpec, :new) | ||
.with_arguments(status: :error) | ||
end | ||
end | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
spec/lib/convenient_service/rspec/helpers/wrap_method_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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
# rubocop:disable RSpec/MultipleMemoizedHelpers | ||
RSpec.describe ConvenientService::RSpec::Helpers::WrapMethod do | ||
include ConvenientService::RSpec::PrimitiveMatchers::DelegateTo | ||
|
||
example_group "instance methods" do | ||
describe "#wrap_method" do | ||
let(:klass) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:instance) { klass.new } | ||
|
||
let(:service_class) do | ||
Class.new do | ||
include ConvenientService::Service::Configs::Standard | ||
|
||
middlewares :result do | ||
observe ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware | ||
end | ||
end | ||
end | ||
|
||
let(:service_instance) { service_class.new } | ||
|
||
let(:entity) { service_instance } | ||
let(:method) { :result } | ||
let(:middleware) { ConvenientService::Service::Plugins::RaisesOnNotResultReturnValue::Middleware } | ||
|
||
specify do | ||
expect { instance.wrap_method(entity, method, observe_middleware: middleware) } | ||
.to delegate_to(ConvenientService::RSpec::Helpers::Classes::WrapMethod, :new) | ||
.with_arguments(entity, method, observe_middleware: middleware) | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/MultipleMemoizedHelpers |
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
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
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
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
32 changes: 32 additions & 0 deletions
32
spec/lib/convenient_service/rspec/primitive_helpers/ignoring_exception_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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
RSpec.describe ConvenientService::RSpec::PrimitiveHelpers::IgnoringException do | ||
include ConvenientService::RSpec::PrimitiveMatchers::DelegateTo | ||
|
||
example_group "instance methods" do | ||
describe "#ignoring_exception" do | ||
let(:klass) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:instance) { klass.new } | ||
|
||
let(:exception) { ArgumentError } | ||
let(:block) { proc { raise exception } } | ||
|
||
specify do | ||
expect { instance.ignoring_exception(exception, &block) } | ||
.to delegate_to(ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException, :new) | ||
.with_arguments(exception, &block) | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
spec/lib/convenient_service/rspec/primitive_helpers/in_threads_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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "convenient_service" | ||
|
||
RSpec.describe ConvenientService::RSpec::PrimitiveHelpers::InThreads do | ||
include ConvenientService::RSpec::PrimitiveMatchers::DelegateTo | ||
|
||
example_group "instance methods" do | ||
describe "#in_threads" do | ||
let(:klass) do | ||
Class.new.tap do |klass| | ||
klass.class_exec(described_class) do |mod| | ||
include mod | ||
end | ||
end | ||
end | ||
|
||
let(:instance) { klass.new } | ||
|
||
let(:n) { 2 } | ||
let(:array) { [] } | ||
let(:block) { proc { |array| array << :foo } } | ||
|
||
specify do | ||
expect { instance.in_threads(n, array, &block) } | ||
.to delegate_to(ConvenientService::RSpec::PrimitiveHelpers::Classes::InThreads, :new) | ||
.with_arguments(n, array, &block) | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.