Class: Marso::Step

Inherits:
Object show all
Includes:
StepPublish
Defined in:
lib/marso/domain/step/step.rb

Overview

A ‘Step’ is a Scenario’s part. It contains a text that describe what that step does, as well as a status that indicates whether or not that step has already been executed. This status can take the following values:

> :none

> :passed

> :failed

> :cancelled

> :error

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StepPublish

#colorized_text

Constructor Details

#initialize(description, scenario_id, color_theme, status = :none, &block) ⇒ Step

Returns a new instance of Step.



20
21
22
23
24
25
26
# File 'lib/marso/domain/step/step.rb', line 20

def initialize(description, scenario_id, color_theme, status=:none, &block)
  @description=description
  @status=status
  @block=block
  @scenario_id=scenario_id
  @color_theme = color_theme
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



18
19
20
# File 'lib/marso/domain/step/step.rb', line 18

def block
  @block
end

#color_themeObject (readonly)

Returns the value of attribute color_theme.



18
19
20
# File 'lib/marso/domain/step/step.rb', line 18

def color_theme
  @color_theme
end

#descriptionObject (readonly)

Returns the value of attribute description.



18
19
20
# File 'lib/marso/domain/step/step.rb', line 18

def description
  @description
end

#scenario_idObject (readonly)

Returns the value of attribute scenario_id.



18
19
20
# File 'lib/marso/domain/step/step.rb', line 18

def scenario_id
  @scenario_id
end

#statusObject (readonly)

Returns the value of attribute status.



18
19
20
# File 'lib/marso/domain/step/step.rb', line 18

def status
  @status
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
# File 'lib/marso/domain/step/step.rb', line 28

def run
  if @status != :cancelled
    execute_block
  else
    return self
  end
end

#text(include_id = false) ⇒ Object

include_id will prepend the scenario id to the step’s description. This can be useful in the case where each step is being output to the console in realtime. In that situation multiple steps from multiple scenarios may be intertwined if they are executed concurently. Without the scenario id, it may be difficult to identify which step belongs to which scenario



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/marso/domain/step/step.rb', line 42

def text(include_id=false)
  body = nil
  case @status
  when :none
    body = "#{@description}"
  when :passed
      body = "#{@description}: PASSED"
  when :failed
    body = "#{@description}: FAILED"
  when :cancelled
    body = "#{@description}: CANCELLED"
  when :error
    body = "#{@description}"
  end

  return include_id ? "#{scenario_id}: #{body}" : body

end