Skip to content

Commit

Permalink
refactor(rspec): split convenient service and primitive helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Sep 26, 2023
1 parent 7d214a5 commit 860357b
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 37 deletions.
1 change: 1 addition & 0 deletions lib/convenient_service/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative "rspec/primitive_helpers"
require_relative "rspec/helpers"

require_relative "rspec/primitive_matchers"
Expand Down
8 changes: 3 additions & 5 deletions lib/convenient_service/rspec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_relative "helpers/classes"

require_relative "helpers/ignoring_exception"
require_relative "helpers/in_threads"
require_relative "helpers/stub_service"
require_relative "helpers/wrap_method"

Expand All @@ -13,10 +12,9 @@ module Helpers
include Support::Concern

included do
include Helpers::IgnoringException
include Helpers::InThreads
include Helpers::StubService
include Helpers::WrapMethod
include IgnoringException
include StubService
include WrapMethod
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/convenient_service/rspec/helpers/classes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# frozen_string_literal: true

require_relative "classes/ignoring_exception"
require_relative "classes/in_threads"
require_relative "classes/stub_service"
require_relative "classes/wrap_method"
2 changes: 1 addition & 1 deletion lib/convenient_service/rspec/helpers/ignoring_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module RSpec
module Helpers
module IgnoringException
def ignoring_exception(...)
Classes::IgnoringException.call(...)
RSpec::PrimitiveHelpers::Classes::IgnoringException.call(...)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/convenient_service/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ module Matchers
include Support::Concern

included do
include Matchers::CallChainNext
include Matchers::DelegateTo
include Matchers::Export
include Matchers::IncludeModule
include Matchers::Results
include CallChainNext
include DelegateTo
include Export
include IncludeModule
include Results
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions lib/convenient_service/rspec/primitive_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require_relative "primitive_helpers/classes"

require_relative "primitive_helpers/ignoring_exception"
require_relative "primitive_helpers/in_threads"

module ConvenientService
module RSpec
module PrimitiveHelpers
include Support::Concern

included do
include IgnoringException
include InThreads
end
end
end
end
4 changes: 4 additions & 0 deletions lib/convenient_service/rspec/primitive_helpers/classes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

require_relative "classes/ignoring_exception"
require_relative "classes/in_threads"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module ConvenientService
module RSpec
module Helpers
module PrimitiveHelpers
module Classes
class IgnoringException < Support::Command
##
Expand All @@ -30,7 +30,7 @@ def initialize(exception, &block)

##
# @return [ConvenientService::Support::UniqueValue]
# @raise [ConvenientService::RSpec::Helpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised]
# @raise [ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised]
#
# @note Rescue `StandardError`, NOT `Exception`.
# @see https://thoughtbot.com/blog/rescue-standarderror-not-exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ConvenientService
module RSpec
module Helpers
module PrimitiveHelpers
module Classes
class IgnoringException < Support::Command
module Exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ConvenientService
module RSpec
module Helpers
module PrimitiveHelpers
module Classes
# @internal
# TODO: Specs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module ConvenientService
module RSpec
module PrimitiveHelpers
module IgnoringException
def ignoring_exception(...)
Classes::IgnoringException.call(...)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ConvenientService
module RSpec
module Helpers
module PrimitiveHelpers
module InThreads
def in_threads(...)
Classes::InThreads.call(...)
Expand Down
26 changes: 13 additions & 13 deletions lib/convenient_service/rspec/primitive_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ module PrimitiveMatchers
include Support::Concern

included do
include PrimitiveMatchers::BeDescendantOf
include PrimitiveMatchers::BeDirectDescendantOf
include PrimitiveMatchers::CacheItsValue
include PrimitiveMatchers::DelegateTo
include PrimitiveMatchers::ExtendModule
include PrimitiveMatchers::HaveAbstractMethod
include PrimitiveMatchers::HaveAliasMethod
include PrimitiveMatchers::HaveAttrAccessor
include PrimitiveMatchers::HaveAttrReader
include PrimitiveMatchers::HaveAttrWriter
include PrimitiveMatchers::IncludeModule
include PrimitiveMatchers::PrependModule
include PrimitiveMatchers::SingletonPrependModule
include BeDescendantOf
include BeDirectDescendantOf
include CacheItsValue
include DelegateTo
include ExtendModule
include HaveAbstractMethod
include HaveAliasMethod
include HaveAttrAccessor
include HaveAttrReader
include HaveAttrWriter
include IncludeModule
include PrependModule
include SingletonPrependModule
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require "convenient_service"

RSpec.describe ConvenientService::RSpec::Helpers::Classes::IgnoringException::Exceptions do
RSpec.describe ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException::Exceptions do
include ConvenientService::RSpec::PrimitiveMatchers::BeDescendantOf

specify { expect(described_class::IgnoredExceptionIsNotRaised).to be_descendant_of(ConvenientService::Exception) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "convenient_service"

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::RSpec::Helpers::Classes::IgnoringException do
RSpec.describe ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException do
include ConvenientService::RSpec::Matchers::DelegateTo

example_group "instance methods" do
Expand All @@ -22,9 +22,9 @@
TEXT
end

it "raises `ConvenientService::RSpec::Helpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised`" do
it "raises `ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised`" do
expect { command_result }
.to raise_error(ConvenientService::RSpec::Helpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised)
.to raise_error(ConvenientService::RSpec::PrimitiveHelpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised)
.with_message(exception_message)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::Support::ThreadSafeCounter do
include ConvenientService::RSpec::Helpers::IgnoringException
include ConvenientService::RSpec::Helpers::InThreads
include ConvenientService::RSpec::PrimitiveHelpers::IgnoringException
include ConvenientService::RSpec::PrimitiveHelpers::InThreads

let(:counter) { described_class.new(initial_value: initial_value, min_value: min_value, max_value: max_value) }
let(:initial_value) { 0 }
Expand Down

0 comments on commit 860357b

Please sign in to comment.