class LightService::Testing::ContextFactory

Attributes

organizer[R]

Public Class Methods

make_from(organizer) click to toggle source
# File lib/light-service/testing/context_factory.rb, line 6
def self.make_from(organizer)
  new(organizer)
end
new(organizer) click to toggle source
# File lib/light-service/testing/context_factory.rb, line 39
def initialize(organizer)
  @organizer = organizer
end

Public Instance Methods

for(action) click to toggle source
# File lib/light-service/testing/context_factory.rb, line 10
def for(action)
  @organizer.append_before_actions(
    lambda do |ctx|
      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) click to toggle source

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

# File lib/light-service/testing/context_factory.rb, line 30
def with(*args, &block)
  catch(:return_ctx_from_execution) do
    @organizer.call(*args, &block)
  end
end