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 ...@@ -49,6 +49,10 @@ module QA
end end
def self.errors def self.errors
if views.empty?
return ["#{name} class does not have views / elements defined!"]
end
@errors ||= views.map(&:errors).flatten @errors ||= views.map(&:errors).flatten
end end
......
...@@ -31,8 +31,8 @@ module QA ...@@ -31,8 +31,8 @@ module QA
@errors ||= Array.new.tap do |errors| @errors ||= Array.new.tap do |errors|
descendants.each do |page| descendants.each do |page|
page.views.each do |view| page.views.each do |view|
view.errors.each do |error| view.errors.each do |message|
errors.push(Error.new(page, view, error)) errors.push(Error.new(page.name, view.path, message))
end end
end end
end end
...@@ -40,11 +40,9 @@ module QA ...@@ -40,11 +40,9 @@ module QA
end end
def validate! def validate!
message = <<~EOS return if errors.none?
We found validation errors!
EOS
raise ValidationError, message if errors.any? raise ValidationError, 'Page views / elements validation error!'
end end
end end
end end
......
...@@ -5,7 +5,18 @@ module QA ...@@ -5,7 +5,18 @@ module QA
class Selectors < Scenario::Template class Selectors < Scenario::Template
include Scenario::Bootable include Scenario::Bootable
PAGE_MODULES = [QA::Page]
def perform(*) 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 end
end end
......
...@@ -36,6 +36,7 @@ describe QA::Page::Base do ...@@ -36,6 +36,7 @@ describe QA::Page::Base do
describe '.errors' do describe '.errors' do
let(:view) { double('view') } let(:view) { double('view') }
context 'when page has views and elements defined' do
before do before do
allow(described_class).to receive(:views) allow(described_class).to receive(:views)
.and_return([view]) .and_return([view])
...@@ -47,4 +48,16 @@ describe QA::Page::Base do ...@@ -47,4 +48,16 @@ describe QA::Page::Base do
expect(described_class.errors).to eq ['some error'] expect(described_class.errors).to eq ['some error']
end end
end end
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 end
...@@ -69,13 +69,9 @@ describe QA::Page::Validator do ...@@ -69,13 +69,9 @@ describe QA::Page::Validator do
end end
describe '#validate!' do describe '#validate!' do
it 'does raises an error with descriptive message' do it 'raises validation error' do
message = <<~EOS
We found validation errors!
EOS
expect { subject.validate! } expect { subject.validate! }
.to raise_error described_class::ValidationError, message .to raise_error described_class::ValidationError
end end
end 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