module Screengem::Actor

Mixin that allows an actor to perform tasks, ask questions, and to remember and recall tagged values.

Return self for those methods that may be chained in the step definition DSL.

The ability to remember and recall values is used to carry state forward from one step definition to another (as the preferred alternative to instance variables).

Question and task instances (aka primitives) are configured with:

(1) a reference to the actor that is interacting with the primitive
(2) a reference to the screen instance that hosts accessors to the screen elements.

Public Instance Methods

asks(*questions) click to toggle source

Used by an actor to ask one or more questions in a step definition.

# File lib/screengem/actor.rb, line 19
def asks(*questions)
  questions.each do |question|
    question.configure(self, screen).answer
  end

  self
end
performs(*tasks) click to toggle source

Used by an actor to perform one or more tasks in a step definition.

# File lib/screengem/actor.rb, line 30
def performs(*tasks)
  tasks.each do |task|
    task.configure(self, screen).perform
  end

  self
end
recall(tag, reload: true) click to toggle source

Used by an actor to recall a value for the specified tag.

# File lib/screengem/actor.rb, line 41
    def recall(tag, reload: true)
      unless recollections.key?(tag)
        raise <<~MSG
          #{name} does not recall #{tag}
          #{name} recalls: #{recollections.keys.to_sentence}
        MSG
      end

      recollections.fetch(tag).tap do |value|
        value.reload if reload && value.respond_to?(:reload)
      end
    end
remember(facts) click to toggle source

Used by an actor to remember one or more tagged values.

# File lib/screengem/actor.rb, line 57
def remember(facts)
  recollections.merge!(facts)

  self
end

Private Instance Methods

recollections() click to toggle source
# File lib/screengem/actor.rb, line 65
def recollections
  ActorMemory.instance.recollections(self)
end
screen() click to toggle source
# File lib/screengem/actor.rb, line 69
def screen
  Screengem::ScreenElements.instance
end