Skip to content

Commit 921e7ec

Browse files
committed
Document Debugging and Rescuing on Failures 🦸
1 parent 3807ee5 commit 921e7ec

File tree

16 files changed

+124
-15
lines changed

16 files changed

+124
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Capybara Test Helpers 1.0.3 (2020-11-24) ##
2+
3+
* Add `CapybaraTestHelpers::BenchmarkHelpers`
4+
15
## Capybara Test Helpers 1.0.2 (2020-11-23) ##
26

37
* Add `aliases` DSL to define `SELECTORS`.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
capybara_test_helpers (1.0.2)
4+
capybara_test_helpers (1.0.3)
55
activesupport
66
capybara
77

docs/.algolia/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"stop_urls": [
1212
"https://capybara-test-helpers.netlify.app/introduction.html",
1313
"https://capybara-test-helpers.netlify.app/installation.html",
14+
"https://capybara-test-helpers.netlify.app/api/index.html",
1415
"https://capybara-test-helpers.netlify.app/guide/index.html",
15-
"https://capybara-test-helpers.netlify.app/guide/advanced/synchronization.html",
1616
"https://capybara-test-helpers.netlify.app/guide/essentials/actions.html",
1717
"https://capybara-test-helpers.netlify.app/guide/essentials/finders.html",
1818
"https://capybara-test-helpers.netlify.app/guide/essentials/querying.html",
@@ -22,6 +22,7 @@
2222
"https://capybara-test-helpers.netlify.app/guide/essentials/injection.html",
2323
"https://capybara-test-helpers.netlify.app/guide/advanced/assertions.html",
2424
"https://capybara-test-helpers.netlify.app/guide/advanced/composition.html",
25+
"https://capybara-test-helpers.netlify.app/guide/advanced/debugging.html",
2526
"https://capybara-test-helpers.netlify.app/guide/advanced/design-patterns.html",
2627
"https://capybara-test-helpers.netlify.app/guide/advanced/filtering.html",
2728
"https://capybara-test-helpers.netlify.app/guide/migrating_from_cucumber/index.html"

docs/.vitepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ const config = {
106106
text: 'Advanced Composition',
107107
link: '/guide/advanced/composition.html',
108108
},
109+
{
110+
text: 'Debugging',
111+
link: '/guide/advanced/debugging.html',
112+
},
109113
{
110114
text: 'Design Patterns',
111115
link: '/guide/advanced/design-patterns.html',

docs/.vitepress/styles/styles.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,37 @@ a.sidebar-link:hover {
2727
color: #cb4e00;
2828
}
2929

30+
.custom-block {
31+
border-bottom-right-radius: 2px;
32+
border-top-right-radius: 2px;
33+
}
34+
3035
.custom-block.custom-block.tip {
3136
background-color: #f7f5f3;
3237
border-color: #f38b54;
3338
}
3439

40+
.custom-block:before {
41+
position: absolute;
42+
top: 19px;
43+
left: -14px;
44+
color: #fff;
45+
width: 20px;
46+
height: 20px;
47+
border-radius: 100%;
48+
text-align: center;
49+
line-height: 20px;
50+
font-weight: 700;
51+
font-size: 14px;
52+
}
53+
54+
.custom-block.tip:before {
55+
content: url(/icons/bulb.svg);
56+
width: 25px;
57+
height: 25px;
58+
left: -16px;
59+
}
60+
3561
details > summary {
3662
cursor: pointer;
3763
}

docs/api/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,16 @@ sidebar: auto
44

55
# API Reference
66

7+
## Actions
8+
9+
## Aliases
10+
11+
## Assertions
12+
13+
## Finders
14+
15+
## Scoping
16+
17+
## Wrapping
18+
719
__Coming Soon__

docs/guide/advanced/debugging.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[pry-rescue]: https://github.com/ConradIrwin/pry-rescue
2+
[pry-stack-explorer]: https://github.com/pry/pry-stack_explorer
3+
4+
# Debugging 🐞
5+
6+
In order to keep track of the interactions being performed in the test, it can be very convenient to print any test helper methods as they are executed, which can also help to detect slow paths.
7+
8+
You can easily achieve this by adding `CapybaraTestHelpers::BenchmarkHelper` to your `BaseTestHelper`:
9+
10+
```ruby
11+
require 'capybara_test_helpers/benchmark_helpers' if ENV['CI']
12+
13+
class BaseTestHelper < Capybara::TestHelper
14+
include CapybaraTestHelpers::BenchmarkHelpers if ENV['CI']
15+
end
16+
```
17+
18+
In the snippet above, we skip the extra output if we are running tests in a continuous integration server.
19+
20+
These helpers need the `rainbow` gem to be installed for nicer output:
21+
22+
```ruby
23+
gem :development, :test do
24+
gem 'rainbow'
25+
end
26+
```
27+
28+
And the result:
29+
30+
![benchmark_helpers](/images/benchmark_helpers.svg)
31+
32+
## Pausing on Failures 🦸
33+
34+
When running tests locally, it can be really helpful to pause and debug when an assertion or find fails.
35+
36+
[`pry-rescue`][pry-rescue] is excellent for this purpose when running integration tests in RSpec. You can install it by adding the following to your Gemfile:
37+
38+
```ruby
39+
group :development do
40+
gem 'pry-rescue'
41+
gem 'pry-stack_explorer'
42+
end
43+
```
44+
45+
and then requiring it in `spec_helper.rb`, `base_test_helper.rb`, or similar:
46+
47+
```ruby
48+
require 'pry-rescue/rspec' unless ENV['CI']
49+
```
50+
51+
Whenever a test fails, it will start an interactive session, allowing you to query the page contents and call any test helper methods:
52+
53+
![benchmark_helpers](/images/pry-rescue.svg)
54+
55+
You can navigate through the stack by running the [`up` and `down` commands][pry-stack-explorer].

docs/public/icons/bulb.svg

Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

docs/public/images/pry-rescue.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)