Class: TestStep

Inherits:
Object show all
Defined in:
lib/test_case/test_step.rb

Overview

The TestStep class defines test step functionality, managing flow and providing hooks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_case, id, name, device, iteration, status: nil, ignore_errors: nil) ⇒ TestStep

Public: Creates a new test step.

test_case - TestCase (subclass) instance. id - Integer test step number. name - String test step name. device - Integer test device id. iteration - Integer test iteration number. status - TestStatus initial status (default: nil). ignore_errors - Boolean indicating the step should ignore any errors (default: nil).

If default, setting from test case will be used.

Returns the new TestStep instance.



20
21
22
23
24
25
26
27
28
29
# File 'lib/test_case/test_step.rb', line 20

def initialize(test_case, id, name, device, iteration, status: nil, ignore_errors: nil)
  @test_case = test_case
  @id = id
  @name = name
  @device = device
  @iteration = iteration
  @status = TestStatus.new(@test_case, status)
  @update = false
  @raising = !(ignore_errors.nil? ? @test_case.test_steps_ignore_errors? : ignore_errors)
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



6
7
8
# File 'lib/test_case/test_step.rb', line 6

def device
  @device
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/test_case/test_step.rb', line 6

def id
  @id
end

#iterationObject (readonly)

Returns the value of attribute iteration.



6
7
8
# File 'lib/test_case/test_step.rb', line 6

def iteration
  @iteration
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/test_case/test_step.rb', line 6

def name
  @name
end

Instance Method Details

#fail(reason = 'Unknown cause', backtrace: nil) ⇒ Object

Public: Fails the test step.

reason - String message describing the reason for failure.

Returns nothing.

Raises:



69
70
71
72
# File 'lib/test_case/test_step.rb', line 69

def fail(reason='Unknown cause', backtrace: nil)
  set_status(TestStatus.new(@test_case, TestStatus::FAILED, reason: reason, backtrace: backtrace || caller))
  raise TestException.new
end

#pass(reason = nil) ⇒ Object

Public: Passes the test step.

reason - String message describing the reason for passing.

Returns nothing.



79
80
81
# File 'lib/test_case/test_step.rb', line 79

def pass(reason=nil)
  set_status(TestStatus.new(@test_case, TestStatus::PASSED, reason: reason))
end

#perform(update: false, &block) ⇒ Object

Public: Performs the test step.

block - Block that performs the step.

Returns nothing.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/test_case/test_step.rb', line 43

def perform(update: false, &block)
  @update = update
  begin
    before_run
    run(&block)
    pass unless status == TestStatus::PASSED
  rescue Exception => e
    if e.is_a?(TestException)
      raise if @raising
    elsif e.is_a?(Minitest::Assertion)
      set_status(TestStatus.new(@test_case, TestStatus::FAILED, exception: e))
      raise TestException.new if @raising
    else
      set_status(TestStatus.new(@test_case, TestStatus::ERROR, exception: e))
      raise TestException.new if @raising || e.is_a?(Interrupt)  # ALWAYS raise Interrupt
    end
  ensure
    after_run
  end
end

#statusObject

Public: Gets step status.

Returns String status.



34
35
36
# File 'lib/test_case/test_step.rb', line 34

def status
  @status.status
end