CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/acceptance/line_validation.rb
Views: 11779
1
module Acceptance
2
###
3
# A utility object representing the validation of a a line of output generated
4
# by the acceptance test suite.
5
###
6
class LineValidation
7
# @param [string|Array<String>] values A line string, or array of lines
8
# @param [Object] options Additional options for configuring this failure, i.e. if it's a known flaky test result etc.
9
def initialize(values, options = {})
10
@values = Array(values)
11
@options = options
12
end
13
14
def flatten
15
@values.map { |value| self.class.new(value, @options) }
16
end
17
18
def value
19
raise StandardError, 'More than one value present' if @values.length > 1
20
21
@values[0]
22
end
23
24
# @return [boolean] returns true if the current failure applies under the current environment or the result is flaky, false otherwise.
25
# @param [Hash] environment The current execution environment
26
# @return [TrueClass, FalseClass] True if the line is flaky - and may not always be present, false otherwise
27
def flaky?(environment = {})
28
value = @options.fetch(:flaky, false)
29
30
evaluate_predicate(value, environment)
31
end
32
33
# @return [boolean] returns true if the current failure applies under the current environment or the result is flaky, false otherwise.
34
# @param [Hash] environment
35
# @return [TrueClass, FalseClass] True if the line should be considered valid, false otherwise
36
def if?(environment = {})
37
value = @options.fetch(:if, true)
38
evaluate_predicate(value, environment)
39
end
40
41
def to_h
42
{
43
values: @values,
44
options: @options
45
}
46
end
47
48
private
49
50
# (see Acceptance::Session#eval_predicate)
51
def evaluate_predicate(value, environment)
52
Acceptance::Session.eval_predicate(value, environment)
53
end
54
end
55
end
56
57