Module: Screengem::Actor

Defined in:
lib/screengem/actor.rb

Overview

Mixin that allows an actor to perform tasks, ask questions, take actions, 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).

Action, question, and task instances are extended with PageReferences so that they can interact with the application via page objects.

Instance Method Summary collapse

Instance Method Details

#asks(*questions) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/screengem/actor.rb', line 18

def asks(*questions)
  questions.each do |question|
    question.configure(self).extend(page_references)

    next if question.answer

    raise incorrect_answer(question)
  end

  self
end

#performs(*tasks) ⇒ Object

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



33
34
35
36
37
38
39
40
41
# File 'lib/screengem/actor.rb', line 33

def performs(*tasks)
  tasks.each do |task|
    task.configure(self).extend(page_references)

    task.perform
  end

  self
end

#recall(tag) ⇒ Object

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



46
47
48
# File 'lib/screengem/actor.rb', line 46

def recall(tag)
  recollections.fetch(tag)
end

#remember(facts) ⇒ Object

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



53
54
55
56
57
# File 'lib/screengem/actor.rb', line 53

def remember(facts)
  recollections.merge!(facts)

  self
end

#takes_action(*actions) ⇒ Object

Used by an actor to take one or more actions.

Used to implement tasks. Actions do not appear in step definitions.



64
65
66
67
68
69
70
# File 'lib/screengem/actor.rb', line 64

def takes_action(*actions)
  actions.each do |action|
    action.configure(self).extend(page_references)

    action.execute
  end
end