summaryrefslogtreecommitdiff
path: root/qa/spec/page
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-12-22 15:22:54 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-12-22 15:22:54 +0100
commit481f461380d4919077c543c51f58e37337167706 (patch)
tree805c6610c741cfa1fcbc2c00e8f45f44ef99cfad /qa/spec/page
parentb51ba96e4dddd847e42f0e41c3e1df2ff58d42e4 (diff)
downloadgitlab-ce-481f461380d4919077c543c51f58e37337167706.tar.gz
Add implementation for matching view elements in QA
Diffstat (limited to 'qa/spec/page')
-rw-r--r--qa/spec/page/view_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/qa/spec/page/view_spec.rb b/qa/spec/page/view_spec.rb
new file mode 100644
index 00000000000..27e83d35de1
--- /dev/null
+++ b/qa/spec/page/view_spec.rb
@@ -0,0 +1,61 @@
+describe QA::Page::View do
+ let(:element) do
+ double('element', name: :something, pattern: /some element/)
+ end
+
+ subject { described_class.new('some/file.html', [element]) }
+
+ describe '.evaluate' do
+ it 'evaluates a block and returns a DSL object' do
+ results = described_class.evaluate do
+ element :something, 'my pattern'
+ element :something_else, /another pattern/
+ end
+
+ expect(results.elements.size).to eq 2
+ end
+ end
+
+ describe '#pathname' do
+ it 'returns an absolute and clean path to the view' do
+ expect(subject.pathname.to_s).not_to include 'qa/page/'
+ expect(subject.pathname.to_s).to include 'some/file.html'
+ end
+ end
+
+ describe '#errors' do
+ let(:file) { spy('file') }
+
+ before do
+ allow(File).to receive(:new).and_return(file)
+ end
+
+ context 'when pattern is found' do
+ before do
+ allow(file).to receive(:foreach)
+ .and_yield('some element').once
+ allow(element).to receive(:matches?)
+ .with('some element').and_return(true)
+ end
+
+ it 'walks through the view and asserts on elements existence' do
+ expect(subject.errors).to be_empty
+ end
+ end
+
+ context 'when pattern has not been found' do
+ before do
+ allow(file).to receive(:foreach)
+ .and_yield('some element').once
+ allow(element).to receive(:matches?)
+ .with('some element').and_return(false)
+ end
+
+ it 'returns an array of errors related to missing elements' do
+ expect(subject.errors).not_to be_empty
+ expect(subject.errors.first)
+ .to match %r(Missing element `.*` in `.*/some/file.html` view)
+ end
+ end
+ end
+end