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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9bccea6e
Commit
9bccea6e
authored
Oct 16, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add LiveDebugger#live_debug to debug Capybara in feature tests.
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
88bd5fa2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
20 deletions
+61
-20
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+30
-19
spec/spec_helper.rb
spec/spec_helper.rb
+1
-0
spec/support/live_debugger.rb
spec/support/live_debugger.rb
+21
-0
spec/support/login_helpers.rb
spec/support/login_helpers.rb
+9
-1
No files found.
doc/development/testing_guide/best_practices.md
View file @
9bccea6e
...
...
@@ -58,6 +58,36 @@ writing one](testing_levels.md#consider-not-writing-a-system-test)!
-
It's ok to look for DOM elements but don't abuse it since it makes the tests
more brittle
#### Debugging Capybara
Sometimes you may need to debug Capybara tests by observing browser behavior.
You can stall Capybara and view the website on the browser by using the
`live_debug`
method in your spec. The current page will be automatically opened
in your default browser.
You may need to sign-in first (the current user's credentials are displayed in
the terminal).
To resume the test run, you only need to press
`c`
.
For example:
```
ruby
$
bin
/
rspec
spec
/
features
/
auto_deploy_spec
.
rb
:
34
Running
via
Spring
preloader
in
process
8999
Run
options:
include
{
:locations
=>
{
"./spec/features/auto_deploy_spec.rb"
=>
[
34
]}}
Current
example
is
paused
for
live
debugging
The
current
user
credentials
are:
user2
/
12345678
Press
'c'
to
continue
the
execution
of
the
example
Please
press
'c'
to
continue
the
execution
of
the
example!
;)
<-
I
pressed
`d`
here
Back
to
the
example!
.
Finished
in
34.51
seconds
(
files
took
0.76702
seconds
to
load
)
1
example
,
0
failures
```
### `let` variables
GitLab's RSpec suite has made extensive use of
`let`
variables to reduce
...
...
@@ -267,25 +297,6 @@ RSpec.configure do |config|
end
```
### Debugging Capybara
Sometimes you may need to debug Capybara tests by observing browser behavior.
You can stall capybara and view the website on the browser by adding a long sleep command in your spec and then opening your browser
to the capybara url.
You can get the capybara url by doing
`puts current_url`
.
You can also get the user's email by doing
`puts user.email`
.
The default password for the user is
`12345678`
.
Example:
```
ruby
puts
current_url
puts
user
.
email
sleep
(
200
)
```
---
[
Return to Testing documentation
](
index.md
)
spec/spec_helper.rb
View file @
9bccea6e
...
...
@@ -49,6 +49,7 @@ RSpec.configure do |config|
config
.
include
LoginHelpers
,
type: :feature
config
.
include
SearchHelpers
,
type: :feature
config
.
include
WaitForRequests
,
:js
config
.
include
LiveDebugger
,
:js
config
.
include
StubConfiguration
config
.
include
EmailHelpers
,
:mailer
,
type: :mailer
config
.
include
TestEnv
...
...
spec/support/live_debugger.rb
0 → 100644
View file @
9bccea6e
require
'io/console'
module
LiveDebugger
def
live_debug
`open
#{
current_url
}
`
puts
"
\n
Current example is paused for live debugging"
puts
"The current user credentials are:
#{
@current_user
.
username
}
/ 12345678"
if
@current_user
puts
"Press 'c' to continue the execution of the example"
loop
do
if
$stdin
.
getch
==
'c'
break
else
puts
"Please press 'c' to continue the execution of the example! ;)"
end
end
puts
"Back to the example!"
end
end
spec/support/login_helpers.rb
View file @
9bccea6e
...
...
@@ -3,6 +3,14 @@ require_relative 'devise_helpers'
module
LoginHelpers
include
DeviseHelpers
# Overriding Devise::Test::IntegrationHelpers#sign_in to store @current_user
# since we may need it in LiveDebugger#live_debug.
def
sign_in
(
resource
,
scope:
nil
)
super
@current_user
=
resource
end
# Internal: Log in as a specific user or a new user of a specific role
#
# user_or_role - User object, or a role to create (e.g., :admin, :user)
...
...
@@ -28,7 +36,7 @@ module LoginHelpers
gitlab_sign_in_with
(
user
,
**
kwargs
)
user
@current_user
=
user
end
def
gitlab_sign_in_via
(
provider
,
user
,
uid
)
...
...
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