thoughtbot / action_dispatch-testing-integration-capybara

MIT License
14 stars 0 forks source link

RSpec hangs when finding non-tag selectors #3

Open cpjmcquillan opened 2 years ago

cpjmcquillan commented 2 years ago

I haven't had a chance to dig into this fully yet, but I've been running into this on a project.

# Works as intended
expect(page).to have_css("h1", class: "text-xl", text: "A large heading")

# Hangs indefinitely
expect(page).to have_css(".text-xl", text: "A large heading")

# Also hangs indefinitely
expect(page).to have_content("A large heading")

# Also also hangs indefinitely
within ".some-class" do
  expect(page).to have_css("h1", class: "text-xl", text: "A large heading")
end

# But, this works!
within "body" do
  expect(page).to have_css("h1", class: "text-xl", text: "A large heading")
end

Over the next couple of days I'll create a repo that reproduces the problem, but I thought I'd share now in case anyone else has run into something similar.

cpjmcquillan commented 2 years ago

I've managed to pinpoint the issue further. There is some sort of infinite-loop bug in super_diff.

When I find time I'll write something up about it (and hopefully fix it), but for now removing that resolves the issue.

cpjmcquillan commented 1 year ago

https://github.com/mcmire/super_diff/issues/161

cpjmcquillan commented 1 year ago

I finally managed to do some more digging into this.

Isolating the issue to super_diff forced me to investigate what was going on more closely.

That gem monkey patches RSpec::Expectations::ExpectationHelper, and debugging the handle_failure method highlighted a discrepancy between the matchers used in request specs and system specs.

In system specs, the matcher is an instance of Capybara::RSpecMatchers::Matchers::HaveSelector as expected.

However in request specs, the matcher is an instance of RSpec::Matchers::BuiltIn::Has.

When this gem includes RSpec matchers with require "capybara/rspec", it's not actually including Capybara's RSpec matchers in our request specs.

To resolve this, we need to include them explicitly

RSpec.configure do |config|
  config.include Capybara::RSpecMatchers, type: :request
end

I'm not sure whether it's worth adding this configuration as part of this gem, or whether a note in the Readme would be sufficient.

Happy to open a pull request for either, depending on what you think is most appropriate @seanpdoyle

seanpdoyle commented 1 year ago

Thank you for digging into this! I think we should investigate bundling this up in some way, but at the very least some documentation guidance would be an improvement on its own.

Just to clarify my own understanding, is this a uniquely RSpec issue, or is it possible that MiniTest struggles in similar ways?

cpjmcquillan commented 1 year ago

Yeah, the issue is confined to RSpec.

You can see the difference between the two in the output for this test run.