Skip to content

Inspect Capybara nodes without walking into the driver - #316

Open
coorasse wants to merge 5 commits into
splitwise:mainfrom
coorasse:capybara-node-inspection
Open

coorasse wants to merge 5 commits into
splitwise:mainfrom
coorasse:capybara-node-inspection

Conversation

@coorasse

@coorasse coorasse commented Oct 20, 2026 •

Copy link
Copy Markdown

When a failing expectation involves a Capybara element (e.g. expect(page.find("button")).to be_disabled), SuperDiff builds the failure message by walking the element's instance variables.

An element holds the session, and through it the driver and the browser connection (pages, network traffic, sockets). With CDP-based drivers like Cuprite/Ferrum this takes minutes, so the spec looks like it's hanging.

This adds an inspection tree builder for Capybara::Node::Base and Capybara::Driver::Node that uses Capybara's own #inspect (e.g. #<Capybara::Node::Element tag="h1" path="/html/body/h1">), mirroring the existing ActionDispatch::Request builder. It's loaded by super_diff/rspec when Capybara is present, or explicitly via require "super_diff/capybara".

Capybara is added to the Rails appraisals so the unit specs can run against a real rack_test session.

Alessandro Rodi and others added 2 commits October 20, 2026 20:54
A Capybara node holds the session, and through it the driver and the
browser connection. Walking its instance variables to build a failure
message can take minutes with CDP-based drivers, so nodes are rendered
with Capybara's own #inspect.
@jas14

jas14 commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Hey @coorasse , thanks for the PR.

There are two parts of SuperDiff's output. The first is the inspection, which affects how the "expected ... to eq/match/whatever ..." output looks. It looks like you've got that covered here; reusing Capybara's own #inspect seems reasonable to me.

The other part, which doesn't seem to be covered by this PR yet, is the diff, which comes below the inspection. See this output screenshot.

I'm not familiar with Capybara, so I can't weigh in with much technical detail about how it should look. But if you don't add an operation tree builder, SuperDiff will select the default operation tree builder, which inspects instance variables, which will presumably do the thing we're trying to avoid here = walk into the driver.

@coorasse

Copy link
Copy Markdown
Author

Thank you Joe for the feedback! I hopefully applied the changes you requested.
I've added a differ for Capybara nodes, so it looks something like this:

- #<Capybara::Node::Element tag="h1" path="/html/body/h1">
+ #<Capybara::Node::Element tag="h2" path="/html/body/h2">

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants