Class: Test

Inherits:
Contextual::Node show all
Includes:
Contextual::Child
Defined in:
lib/contextual/test.rb

Overview

A Test is an actionable unit of testing.

Instance Attribute Summary collapse

Attributes inherited from Contextual::Node

#result, #skip

Instance Method Summary collapse

Methods included from Contextual::Child

#assign_parent

Methods inherited from Contextual::Node

#run, #run_setup, #run_teardown, #should_run_with_search_term

Constructor Details

#initialize(title, assertions:, setup: nil, teardown: nil, action: nil, options: nil, skip: false) ⇒ Test

Returns a new instance of Test.

Parameters:

  • title (String)
  • assertions (Proc)
  • action (Proc) (defaults to: nil)
  • skip (Boolean) (defaults to: false)
  • options (TestOptions) (defaults to: nil)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/contextual/test.rb', line 21

def initialize(
  title,
  assertions:,
  setup: nil,
  teardown: nil,
  action: nil,
  options: nil,
  skip: false
)
  super(title, setup: setup, teardown: teardown, options: options, skip: skip)
  @action = action
  @assertions = assertions
  @assert_failures = []
end

Instance Attribute Details

#ran_successfullyBoolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/contextual/test.rb', line 14

def ran_successfully
  @ran_successfully
end

Instance Method Details

#get_result(filter_settings) ⇒ TestResult

Parameters:

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/contextual/test.rb', line 65

def get_result(filter_settings)
  super

  @result = run_setup

  unless @result.nil?
    # Setup failed, we want to bail out as soon as possible
    @ran_successfully = false
    return @result
  end

  run_action

  run_assertions

  teardown_failure = run_teardown
  unless teardown_failure.nil?
    @ran_successfully = false
    @result = teardown_failure
  end

  # At this point, if nothing has failed, this test ran successfully
  @ran_successfully = true if @ran_successfully.nil?
  @result
end

#reportvoid

This method returns an undefined value.

Report results, if any



55
56
57
58
59
60
61
# File 'lib/contextual/test.rb', line 55

def report(*)
  @result.report(@parent_count)

  @assert_failures.each do |assert_failure|
    assert_failure.report(@parent_count)
  end
end

#should_run_with_filter(filter_settings) ⇒ Boolean

Should this run with the current filter settings

Parameters:

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/contextual/test.rb', line 46

def should_run_with_filter(filter_settings)
  return filter_settings.testSearchFor == _title if filter_settings.hasTestSearchFor
  return _title.include? filter_settings.testFilterTerm if filter_settings.hasTestFilterTerm

  should_run_with_search_term(filter_settings)
end