Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
39892f8d
Commit
39892f8d
authored
Dec 22, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add implementation for matching view elements in QA
parent
9ce69872
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
0 deletions
+116
-0
qa/qa/page/base.rb
qa/qa/page/base.rb
+4
-0
qa/qa/page/element.rb
qa/qa/page/element.rb
+12
-0
qa/qa/page/validator.rb
qa/qa/page/validator.rb
+18
-0
qa/qa/page/view.rb
qa/qa/page/view.rb
+21
-0
qa/spec/page/view_spec.rb
qa/spec/page/view_spec.rb
+61
-0
No files found.
qa/qa/page/base.rb
View file @
39892f8d
...
...
@@ -48,6 +48,10 @@ module QA
@evaluator
||=
Page
::
Base
::
DSL
.
new
end
def
self
.
validator
Page
::
Validator
.
new
(
self
)
end
class
DSL
attr_reader
:views
...
...
qa/qa/page/element.rb
View file @
39892f8d
...
...
@@ -7,6 +7,18 @@ module QA
@name
=
name
@pattern
=
pattern
end
def
expression?
@pattern
.
is_a?
(
Regexp
)
end
def
matches?
(
line
)
if
expression?
line
=~
pattern
else
line
.
includes?
(
pattern
)
end
end
end
end
end
qa/qa/page/validator.rb
0 → 100644
View file @
39892f8d
module
QA
module
Page
class
Validator
def
initialize
(
page
)
@page
=
page
@views
=
page
.
views
end
def
errors
@errors
||=
@views
.
map
do
|
view
|
end
end
def
message
end
end
end
end
qa/qa/page/view.rb
View file @
39892f8d
...
...
@@ -8,6 +8,27 @@ module QA
@elements
=
elements
end
def
pathname
Pathname
.
new
(
File
.
join
(
__dir__
,
'../../../'
,
@path
))
.
cleanpath
.
expand_path
end
def
errors
##
# Reduce required elements by streaming views and making assertions on
# elements' patterns.
#
@missing
||=
@elements
.
dup
.
tap
do
|
elements
|
File
.
new
(
pathname
.
to_s
).
foreach
do
|
line
|
elements
.
reject!
{
|
element
|
element
.
matches?
(
line
)
}
end
end
@missing
.
map
do
|
missing
|
"Missing element `
#{
missing
}
` in `
#{
pathname
}
` view partial!"
end
end
def
self
.
evaluate
(
&
block
)
Page
::
View
::
DSL
.
new
.
tap
do
|
evaluator
|
evaluator
.
instance_exec
(
&
block
)
...
...
qa/spec/page/view_spec.rb
0 → 100644
View file @
39892f8d
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment