summaryrefslogtreecommitdiff
path: root/qa/spec/page/validator_spec.rb
blob: 02822d7d18f3a97cf3a2871d56b79a6614cb0c96 (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
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
describe QA::Page::Validator do
  describe '#constants' do
    subject do
      described_class.new(QA::Page::Project)
    end

    it 'returns all constants that are module children' do
      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
      allow(QA::Page::Admin::Settings)
        .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
        it 'raises validation error' do
          expect { subject.validate! }
            .to raise_error described_class::ValidationError
        end
      end
    end
  end
end