Commit 052edb3d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Append page validation error if view partial is missing

parent 8e5d5d3d
...@@ -9,11 +9,15 @@ module QA ...@@ -9,11 +9,15 @@ module QA
end end
def pathname def pathname
Pathname.new(File.join( __dir__, '../../../', @path)) @pathname ||= Pathname.new(File.join( __dir__, '../../../', @path))
.cleanpath.expand_path .cleanpath.expand_path
end end
def errors def errors
unless pathname.readable?
return ["Missing view partial `#{pathname}`!"]
end
## ##
# Reduce required elements by streaming view and making assertions on # Reduce required elements by streaming view and making assertions on
# elements' existence. # elements' existence.
......
...@@ -30,36 +30,47 @@ describe QA::Page::View do ...@@ -30,36 +30,47 @@ describe QA::Page::View do
allow(File).to receive(:new).and_return(file) allow(File).to receive(:new).and_return(file)
end end
context 'when pattern is found' do context 'when view partial is present' do
before do before do
allow(file).to receive(:foreach) allow(subject.pathname).to receive(:readable?)
.and_yield('some element').once .and_return(true)
allow(element).to receive(:matches?)
.with('some element').and_return(true)
end end
it 'walks through the view and asserts on elements existence' do context 'when pattern is found' do
expect(subject.errors).to be_empty before do
end allow(file).to receive(:foreach)
end .and_yield('some element').once
allow(element).to receive(:matches?)
.with('some element').and_return(true)
end
context 'when pattern has not been found' do it 'walks through the view and asserts on elements existence' do
before do expect(subject.errors).to be_empty
allow(file).to receive(:foreach) end
.and_yield('some element').once
allow(element).to receive(:matches?)
.with('some element').and_return(false)
end end
it 'returns an array of errors related to missing elements' do context 'when pattern has not been found' do
expect(subject.errors).not_to be_empty before do
expect(subject.errors.first) allow(file).to receive(:foreach)
.to match %r(Missing element `.*` in `.*/some/file.html` view) .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 end
context 'when view partial has not been found' do context 'when view partial has not been found' do
pending it 'returns an error when it is not able to find the partial' do
expect(subject.errors).to be_one
expect(subject.errors.first)
.to match %r(Missing view partial `.*/some/file.html`!)
end
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