Skip to content

Commit

Permalink
Refactor Deferred::Dsl::Hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepingkingstudios committed May 28, 2024
1 parent 5f7df08 commit 34c35be
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 364 deletions.
1 change: 1 addition & 0 deletions lib/rspec/sleeping_king_studios/deferred/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ module Dsl; end

require 'rspec/sleeping_king_studios/deferred/dsl/examples'
require 'rspec/sleeping_king_studios/deferred/dsl/example_groups'
require 'rspec/sleeping_king_studios/deferred/dsl/hooks'
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# frozen_string_literal: true

require 'rspec/sleeping_king_studios/deferred/calls/hook'
require 'rspec/sleeping_king_studios/deferred/definitions'
require 'rspec/sleeping_king_studios/deferred/examples'
require 'rspec/sleeping_king_studios/deferred/dsl'

module RSpec::SleepingKingStudios::Deferred::Examples
module RSpec::SleepingKingStudios::Deferred::Dsl # rubocop:disable Style/Documentation
# Domain-specific language for defining deferred hooks.
module Hooks
include RSpec::SleepingKingStudios::Deferred::Definitions

# Defines a deferred hook using the #after method.
#
# @param scope [Symbol] the scope for the hook. Must be one of :context,
Expand Down Expand Up @@ -85,6 +82,11 @@ def before(scope, *flags, **conditions, &block)
)
end

# @api private
def deferred_hooks
@deferred_hooks ||= []
end

# Defines a deferred hook using the #prepend_before method.
#
# @param scope [Symbol] the scope for the hook. Must be one of :context,
Expand All @@ -104,12 +106,6 @@ def prepend_before(scope, *flags, **conditions, &block)
)
end

protected

def deferred_hooks
@deferred_hooks ||= []
end

private

def group_hooks
Expand All @@ -128,4 +124,6 @@ def grouped_deferred_calls
super.merge(hooks: group_hooks)
end
end

include Hooks
end
2 changes: 1 addition & 1 deletion lib/rspec/sleeping_king_studios/deferred/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.included(other)
super

other.extend(RSpec::SleepingKingStudios::Deferred::Examples::Dsl)
other.extend(RSpec::SleepingKingStudios::Deferred::Examples::Hooks)
other.extend(RSpec::SleepingKingStudios::Deferred::Dsl::Hooks)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'rspec/sleeping_king_studios/concerns/example_constants'
require 'rspec/sleeping_king_studios/deferred/definitions'
require 'rspec/sleeping_king_studios/deferred/dsl/example_groups'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'rspec/sleeping_king_studios/concerns/example_constants'
require 'rspec/sleeping_king_studios/deferred/definitions'
require 'rspec/sleeping_king_studios/deferred/dsl/examples'

Expand Down
33 changes: 33 additions & 0 deletions spec/rspec/sleeping_king_studios/deferred/dsl/hooks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'rspec/sleeping_king_studios/concerns/example_constants'
require 'rspec/sleeping_king_studios/deferred/definitions'
require 'rspec/sleeping_king_studios/deferred/dsl/hooks'

RSpec.describe RSpec::SleepingKingStudios::Deferred::Dsl::Hooks do
extend RSpec::SleepingKingStudios::Concerns::ExampleConstants
include Spec::Support::SharedExamples::DeferredExamples

subject(:definitions) { described_class }

let(:described_class) { Spec::DeferredExamples }
let(:ancestor_class) { Spec::InheritedExamples }
let(:ancestor_examples) { ancestor_class }

example_constant 'Spec::InheritedExamples' do
Module.new do
extend RSpec::SleepingKingStudios::Deferred::Definitions
extend RSpec::SleepingKingStudios::Deferred::Dsl::Hooks
end
end

example_constant 'Spec::DeferredExamples' do
Module.new do
extend RSpec::SleepingKingStudios::Deferred::Definitions
extend RSpec::SleepingKingStudios::Deferred::Dsl::Hooks
include Spec::InheritedExamples
end
end

include_examples 'should define deferred hooks'
end
2 changes: 2 additions & 0 deletions spec/rspec/sleeping_king_studios/deferred/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
include_examples 'should define deferred examples'

include_examples 'should define deferred example groups'

include_examples 'should define deferred hooks'
end
Loading

0 comments on commit 34c35be

Please sign in to comment.