Skip to content

Commit 58e8189

Browse files
jonasjabarigitbook-bot
authored andcommitted
GitBook: [main] 2 pages modified
1 parent 9d4245d commit 58e8189

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
## Testing
8080

81-
* [Capybara & Rspec \[WIP\]](testing/capybara-and-rspec.md)
81+
* [Capybara & Rspec](testing/capybara-and-rspec.md)
8282

8383
## Community
8484

docs/testing/capybara-and-rspec.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Capybara & Rspec \[WIP\]
1+
# Capybara & Rspec
22

33
Matestack apps, pages and components can be tested with various test setups. We're using Rspec and Capybara a lot when creating apps with Matestack or work on Matestack's core itself and want to show you some basic elements of this setup.
44

@@ -257,5 +257,36 @@ Without adding `expect(page).to have_content("succeeded!")` after `click "submit
257257

258258
Above described approaches and hints apply for actions as well!
259259

260-
## Optional: Dockerized test setup \[WIP\]
260+
## Debugging specs
261+
262+
When running specs in a headless browser, you're loosing insights on what exactly happens when a spec is failing. You have a simple yet powerful option to overcome this issue:
263+
264+
As described within the Setup section, it's possible to tell Capybara, which port should be used by the webserver while executing the specs. \(By default it's randomly chosen on every spec run\). When adding a simple `sleep` after a `visit` in your spec, you can request the same page, your spec would visit in you local browser and review what's going on there by manually executing the steps your spec would perform while reviewing the DOM and browser debugging tools:
265+
266+
{% tabs %}
267+
{% tab title="spec/features/form\_submission\_spec.rb" %}
268+
```ruby
269+
270+
describe "Some Page", type: :feature, js: true do
271+
272+
it "should render hello world" do
273+
visit some_page_path
274+
275+
p some_page_path # see the resolved URL string, copy to your browser
276+
sleep # add the sleep after the visit
277+
278+
fill_in "Name", with: "Foo"
279+
click "submit me"
280+
281+
expect(page).to have_content("succeeded!")
282+
end
283+
284+
end
285+
```
286+
{% endtab %}
287+
{% endtabs %}
288+
289+
Execute the spec and then visit the logged path in your local browser via `localhost:33123/xyz` for example.
290+
291+
This approach is especially useful when using factories in order to create temporary test data which is only accessible in your test ENV and that specific spec. In other words: you can review the test state way better compared to perform the spec steps in your local development ENV.
261292

0 commit comments

Comments
 (0)