Skip to content

Commit

Permalink
feat(be_result): introduce be_result
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Sep 11, 2023
1 parent 8b9a254 commit f8fc85b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/convenient_service/rspec/matchers/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require_relative "results/be_not_failure"
require_relative "results/be_not_success"

require_relative "results/be_result"

module ConvenientService
module RSpec
module Matchers
Expand All @@ -22,6 +24,8 @@ module Results
include Results::BeNotError
include Results::BeNotFailure
include Results::BeNotSuccess

include Results::BeResult
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions lib/convenient_service/rspec/matchers/results/be_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module ConvenientService
module RSpec
module Matchers
module Results
module BeResult
##
# @api public
#
def be_result(status, *args, **kwargs, &block)
case status
when :success
Custom::Results::BeSuccess.new(*args, **kwargs, &block)
when :failure
Custom::Results::BeFailure.new(*args, **kwargs, &block)
when :error
Custom::Results::BeError.new(*args, **kwargs, &block)
when :not_success
Custom::Results::BeNotSuccess.new(*args, **kwargs, &block)
when :not_failure
Custom::Results::BeNotFailure.new(*args, **kwargs, &block)
when :not_error
Custom::Results::BeNotError.new(*args, **kwargs, &block)
end
end
end
end
end
end
end
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::Matchers::Results::BeResult do
include ConvenientService::RSpec::Matchers::Results

specify do
expect(be_result(:success)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeSuccess.new)
end

specify do
expect(be_result(:failure)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeFailure.new)
end

specify do
expect(be_result(:error)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeError.new)
end

specify do
expect(be_result(:not_success)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeNotSuccess.new)
end

specify do
expect(be_result(:not_failure)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeNotFailure.new)
end

specify do
expect(be_result(:not_error)).to eq(ConvenientService::RSpec::Matchers::Custom::Results::BeNotError.new)
end
end
35 changes: 35 additions & 0 deletions spec/lib/convenient_service/rspec/matchers/results_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

RSpec.describe ConvenientService::RSpec::Matchers::Results do
example_group "modules" do
include ConvenientService::RSpec::Matchers::IncludeModule

subject { described_class }

it { is_expected.to include_module(ConvenientService::Support::Concern) }

context "when included" do
subject { klass }

let(:klass) do
Class.new.tap do |klass|
klass.class_exec(described_class) do |mod|
include mod
end
end
end

it { is_expected.to include_module(described_class::BeError) }
it { is_expected.to include_module(described_class::BeFailure) }
it { is_expected.to include_module(described_class::BeSuccess) }
it { is_expected.to include_module(described_class::BeNotError) }
it { is_expected.to include_module(described_class::BeNotFailure) }
it { is_expected.to include_module(described_class::BeNotSuccess) }
it { is_expected.to include_module(described_class::BeResult) }
end
end
end

0 comments on commit f8fc85b

Please sign in to comment.