blob: edd12665f1eaea5bc4ab87bcdeb3616de10be629 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# frozen_string_literal: true
module QA
module Page
class Validator
ValidationError = Class.new(StandardError)
Error = Struct.new(:page, :message) do
def to_s
"Error: #{page} - #{message}"
end
end
def initialize(constant)
@module = constant
end
def constants
@consts ||= @module.constants.map do |const|
@module.const_get(const)
end
end
def descendants
@descendants ||= constants.map do |const|
case const
when Class
const if const < Page::Base
when Module
Page::Validator.new(const).descendants
end
end
@descendants.flatten.compact
end
def errors
[].tap do |errors|
descendants.each do |page|
page.errors.each do |message|
errors.push(Error.new(page.name, message))
end
end
end
end
def validate!
return if errors.none?
raise ValidationError, 'Page views / elements validation error!'
end
end
end
end
|