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
9f2a4ed5
Commit
9f2a4ed5
authored
Jan 09, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement QA pages and views validator
parent
0c3caffa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
0 deletions
+135
-0
qa/qa.rb
qa/qa.rb
+1
-0
qa/qa/page/validator.rb
qa/qa/page/validator.rb
+51
-0
qa/spec/page/validator_spec.rb
qa/spec/page/validator_spec.rb
+83
-0
No files found.
qa/qa.rb
View file @
9f2a4ed5
...
@@ -74,6 +74,7 @@ module QA
...
@@ -74,6 +74,7 @@ module QA
autoload
:Base
,
'qa/page/base'
autoload
:Base
,
'qa/page/base'
autoload
:View
,
'qa/page/view'
autoload
:View
,
'qa/page/view'
autoload
:Element
,
'qa/page/element'
autoload
:Element
,
'qa/page/element'
autoload
:Validator
,
'qa/page/validator'
module
Main
module
Main
autoload
:Login
,
'qa/page/main/login'
autoload
:Login
,
'qa/page/main/login'
...
...
qa/qa/page/validator.rb
0 → 100644
View file @
9f2a4ed5
module
QA
module
Page
class
Validator
ValidationError
=
Class
.
new
(
StandardError
)
Error
=
Struct
.
new
(
:page
,
:view
,
:message
)
def
initialize
(
constant
)
@module
=
constant
end
def
constants
@consts
||=
@module
.
constants
.
map
do
|
const
|
@module
.
const_get
(
const
)
end
end
def
descendants
@descendants
||=
constants
.
map
do
|
const
|
case
const
when
Class
const
if
const
<
Page
::
Base
when
Module
Page
::
Validator
.
new
(
const
).
descendants
end
end
@descendants
.
flatten
.
compact
end
def
errors
@errors
||=
Array
.
new
.
tap
do
|
errors
|
descendants
.
each
do
|
page
|
page
.
views
.
each
do
|
view
|
view
.
errors
.
each
do
|
error
|
errors
.
push
(
Error
.
new
(
page
,
view
,
error
))
end
end
end
end
end
def
validate!
message
=
<<~
EOS
We found validation errors!
EOS
raise
ValidationError
,
message
if
errors
.
any?
end
end
end
end
qa/spec/page/validator_spec.rb
0 → 100644
View file @
9f2a4ed5
describe
QA
::
Page
::
Validator
do
describe
'#constants'
do
subject
do
described_class
.
new
(
QA
::
Page
::
Project
)
end
it
'returns all costants 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
'does raises an error with descriptive message'
do
message
=
<<~
EOS
We found validation errors!
EOS
expect
{
subject
.
validate!
}
.
to
raise_error
described_class
::
ValidationError
,
message
end
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