Class: FunctionalLightService::Testing::ContextFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/functional-light-service/testing/context_factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organizer) ⇒ ContextFactory

rubocop:enable Style/ArgumentsForwarding



37
38
39
# File 'lib/functional-light-service/testing/context_factory.rb', line 37

def initialize(organizer)
  @organizer = organizer
end

Instance Attribute Details

#organizerObject (readonly)

Returns the value of attribute organizer.



4
5
6
# File 'lib/functional-light-service/testing/context_factory.rb', line 4

def organizer
  @organizer
end

Class Method Details

.make_from(organizer) ⇒ Object



6
7
8
# File 'lib/functional-light-service/testing/context_factory.rb', line 6

def self.make_from(organizer)
  new(organizer)
end

Instance Method Details

#for(action) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/functional-light-service/testing/context_factory.rb', line 10

def for(action)
  @organizer.append_before_actions(
    ->(ctx) do
      if ctx.current_action == action
        # The last `:_before_actions` hook is for
        # ContextFactory, remove it, so it won't
        # be invoked again
        ctx[:_before_actions].pop

        throw(:return_ctx_from_execution, ctx)
      end
    end
  )

  self
end

#with(*args, &block) ⇒ Object

More than one arguments can be passed to the Organizer's #call method rubocop:disable Style/ArgumentsForwarding



30
31
32
33
34
# File 'lib/functional-light-service/testing/context_factory.rb', line 30

def with(*args, &block)
  catch(:return_ctx_from_execution) do
    @organizer.call(*args, &block)
  end
end