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
4b945e28
Commit
4b945e28
authored
Jan 09, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to define a QA-specific page element
parent
489267e6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
19 deletions
+23
-19
qa/qa/page/element.rb
qa/qa/page/element.rb
+10
-9
qa/qa/page/view.rb
qa/qa/page/view.rb
+1
-1
qa/spec/page/element_spec.rb
qa/spec/page/element_spec.rb
+12
-9
No files found.
qa/qa/page/element.rb
View file @
4b945e28
...
...
@@ -3,20 +3,21 @@ module QA
class
Element
attr_reader
:name
def
initialize
(
name
,
pattern
)
def
initialize
(
name
,
pattern
=
nil
)
@name
=
name
@pattern
=
pattern
@pattern
=
pattern
||
"qa-
#{
@name
.
to_s
.
gsub
(
'_'
,
'-'
)
}
"
end
def
matches?
(
line
)
case
@pattern
when
Regexp
!!
(
line
=~
@pattern
)
when
String
line
.
include?
(
@pattern
)
def
expression
if
@pattern
.
is_a?
(
String
)
@_regexp
||=
Regexp
.
new
(
Regexp
.
escape
(
@pattern
))
else
raise
ArgumentError
,
'Pattern should be either String or Regexp!'
@pattern
end
end
def
matches?
(
line
)
!!
(
line
=~
expression
)
end
end
end
...
...
qa/qa/page/view.rb
View file @
4b945e28
...
...
@@ -46,7 +46,7 @@ module QA
@elements
=
[]
end
def
element
(
name
,
pattern
)
def
element
(
name
,
pattern
=
nil
)
@elements
.
push
(
Page
::
Element
.
new
(
name
,
pattern
))
end
end
...
...
qa/spec/page/element_spec.rb
View file @
4b945e28
...
...
@@ -2,11 +2,11 @@ describe QA::Page::Element do
context
'when pattern is an expression'
do
subject
{
described_class
.
new
(
:something
,
/button 'Sign in'/
)
}
it
'
is correctly matches against a string
'
do
it
'
matches when there is a match
'
do
expect
(
subject
.
matches?
(
"button 'Sign in'"
)).
to
be
true
end
it
'does not match if
string does not match against a pattern
'
do
it
'does not match if
pattern is not present
'
do
expect
(
subject
.
matches?
(
"button 'Sign out'"
)).
to
be
false
end
end
...
...
@@ -14,21 +14,24 @@ describe QA::Page::Element do
context
'when pattern is a string'
do
subject
{
described_class
.
new
(
:something
,
'button'
)
}
it
'
is correctly matches against a string
'
do
it
'
matches when there is match
'
do
expect
(
subject
.
matches?
(
'some button in the view'
)).
to
be
true
end
it
'does not match if
string does not match against a pattern
'
do
it
'does not match if
pattern is not present
'
do
expect
(
subject
.
matches?
(
'text_field :name'
)).
to
be
false
end
end
context
'when pattern is not
support
ed'
do
subject
{
described_class
.
new
(
:some
thing
,
[
/something/
]
)
}
context
'when pattern is not
provid
ed'
do
subject
{
described_class
.
new
(
:some
_name
)
}
it
'raises an error'
do
expect
{
subject
.
matches?
(
'some line'
)
}
.
to
raise_error
ArgumentError
it
'matches when QA specific selector is present'
do
expect
(
subject
.
matches?
(
'some qa-some-name selector'
)).
to
be
true
end
it
'does not match if QA selector is not there'
do
expect
(
subject
.
matches?
(
'some_name selector'
)).
to
be
false
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