2019-04-11 08:02:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-09 05:28:14 -05:00
|
|
|
describe QA::Page::Validator do
|
|
|
|
describe '#constants' do
|
|
|
|
subject do
|
|
|
|
described_class.new(QA::Page::Project)
|
|
|
|
end
|
|
|
|
|
2018-01-10 05:15:57 -05:00
|
|
|
it 'returns all constants that are module children' do
|
2018-01-09 05:28:14 -05:00
|
|
|
expect(subject.constants)
|
|
|
|
.to include QA::Page::Project::New, QA::Page::Project::Settings
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#descendants' do
|
|
|
|
subject do
|
|
|
|
described_class.new(QA::Page::Project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'recursively returns all descendants that are page objects' do
|
|
|
|
expect(subject.descendants)
|
|
|
|
.to include QA::Page::Project::New, QA::Page::Project::Settings::Repository
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return modules that aggregate page objects' do
|
|
|
|
expect(subject.descendants)
|
|
|
|
.not_to include QA::Page::Project::Settings
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when checking validation errors' do
|
|
|
|
let(:view) { spy('view') }
|
|
|
|
|
|
|
|
before do
|
2018-10-02 05:45:48 -04:00
|
|
|
allow(QA::Page::Admin::Settings::Repository)
|
2018-01-09 05:28:14 -05:00
|
|
|
.to receive(:views).and_return([view])
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(QA::Page::Admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no validation errors' do
|
|
|
|
before do
|
|
|
|
allow(view).to receive(:errors).and_return([])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'does not return errors' do
|
|
|
|
expect(subject.errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#validate!' do
|
|
|
|
it 'does not raise error' do
|
|
|
|
expect { subject.validate! }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are validation errors' do
|
|
|
|
before do
|
|
|
|
allow(view).to receive(:errors)
|
|
|
|
.and_return(['some error', 'another error'])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'returns errors' do
|
|
|
|
expect(subject.errors.count).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#validate!' do
|
2018-01-09 06:06:58 -05:00
|
|
|
it 'raises validation error' do
|
2018-01-09 05:28:14 -05:00
|
|
|
expect { subject.validate! }
|
2018-01-09 06:06:58 -05:00
|
|
|
.to raise_error described_class::ValidationError
|
2018-01-09 05:28:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|