43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/testcentricity_web/exception_queue_helper.rb', line 43
def self.enqueue_comparison(ui_object, state, actual, error_msg)
@active_ui_element = ui_object
if state.is_a?(Hash) && state.length == 1
state.each do |key, value|
case key
when :lt, :less_than
enqueue_exception("#{error_msg} be less than #{value} but found '#{actual}'") unless actual < value
when :lt_eq, :less_than_or_equal
enqueue_exception("#{error_msg} be less than or equal to #{value} but found '#{actual}'") unless actual <= value
when :gt, :greater_than
enqueue_exception("#{error_msg} be greater than #{value} but found '#{actual}'") unless actual > value
when :gt_eq, :greater_than_or_equal
enqueue_exception("#{error_msg} be greater than or equal to #{value} but found '#{actual}'") unless actual >= value
when :starts_with
enqueue_exception("#{error_msg} start with '#{value}' but found '#{actual}'") unless actual.start_with?(value)
when :ends_with
enqueue_exception("#{error_msg} end with '#{value}' but found '#{actual}'") unless actual.end_with?(value)
when :contains
enqueue_exception("#{error_msg} contain '#{value}' but found '#{actual}'") unless actual.include?(value)
when :not_contains, :does_not_contain
enqueue_exception("#{error_msg} not contain '#{value}' but found '#{actual}'") if actual.include?(value)
when :not_equal
enqueue_exception("#{error_msg} not equal '#{value}' but found '#{actual}'") if actual == value
when :like, :is_like
actual_like = actual.delete("\n")
actual_like = actual_like.delete("\r")
actual_like = actual_like.delete("\t")
actual_like = actual_like.delete(' ')
actual_like = actual_like.downcase
expected = value.delete("\n")
expected = expected.delete("\r")
expected = expected.delete("\t")
expected = expected.delete(' ')
expected = expected.downcase
enqueue_exception("#{error_msg} be like '#{value}' but found '#{actual}'") unless actual_like.include?(expected)
when :translate
expected = translate(value)
enqueue_assert_equal(expected, actual, error_msg)
when :translate_upcase
expected = translate(value)
expected = expected.is_a?(Array) ? expected.map(&:upcase) : expected.upcase
enqueue_assert_equal(expected, actual, error_msg)
when :translate_downcase
expected = translate(value)
expected = expected.is_a?(Array) ? expected.map(&:downcase) : expected.downcase
enqueue_assert_equal(expected, actual, error_msg)
when :translate_capitalize
expected = translate(value)
expected = expected.is_a?(Array) ? expected.map(&:capitalize) : expected.capitalize
enqueue_assert_equal(expected, actual, error_msg)
when :translate_titlecase
expected = translate(value)
expected = if expected.is_a?(Array)
result = []
expected.each do |item|
result.push("#{item.split.each{ |item| item.capitalize! }.join(' ')}")
end
result
else
"#{expected.split.each{ |expected| expected.capitalize! }.join(' ')}"
end
enqueue_assert_equal(expected, actual, error_msg)
else
raise "#{key} is not a valid comparison key"
end
end
else
enqueue_assert_equal(state, actual, error_msg)
end
end
|