Commit fa07d232 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add QA error when page class has no views defined

parent a5cfd5a6
......@@ -49,6 +49,10 @@ module QA
end
def self.errors
if views.empty?
return ["#{name} class does not have views / elements defined!"]
end
@errors ||= views.map(&:errors).flatten
end
......
......@@ -31,8 +31,8 @@ module QA
@errors ||= Array.new.tap do |errors|
descendants.each do |page|
page.views.each do |view|
view.errors.each do |error|
errors.push(Error.new(page, view, error))
view.errors.each do |message|
errors.push(Error.new(page.name, view.path, message))
end
end
end
......@@ -40,11 +40,9 @@ module QA
end
def validate!
message = <<~EOS
We found validation errors!
EOS
return if errors.none?
raise ValidationError, message if errors.any?
raise ValidationError, 'Page views / elements validation error!'
end
end
end
......
......@@ -5,7 +5,18 @@ module QA
class Selectors < Scenario::Template
include Scenario::Bootable
PAGE_MODULES = [QA::Page]
def perform(*)
validators = PAGE_MODULES.map do |pages|
Page::Validator.new(pages)
end
validators.map(&:errors).flatten.tap do |errors|
end
validators.each(&:validate!)
end
end
end
......
......@@ -36,15 +36,28 @@ describe QA::Page::Base do
describe '.errors' do
let(:view) { double('view') }
before do
allow(described_class).to receive(:views)
.and_return([view])
context 'when page has views and elements defined' do
before do
allow(described_class).to receive(:views)
.and_return([view])
allow(view).to receive(:errors).and_return(['some error'])
allow(view).to receive(:errors).and_return(['some error'])
end
it 'iterates views composite and returns errors' do
expect(described_class.errors).to eq ['some error']
end
end
it 'iterates views composite and returns errors' do
expect(described_class.errors).to eq ['some error']
context 'when page has no views and elements defined' do
before do
allow(described_class).to receive(:views).and_return([])
end
it 'appends an error about missing views / elements block' do
expect(described_class.errors)
.to include 'QA::Page::Base class does not have views / elements defined!'
end
end
end
end
......@@ -69,13 +69,9 @@ describe QA::Page::Validator do
end
describe '#validate!' do
it 'does raises an error with descriptive message' do
message = <<~EOS
We found validation errors!
EOS
it 'raises validation error' do
expect { subject.validate! }
.to raise_error described_class::ValidationError, message
.to raise_error described_class::ValidationError
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment