Rspec: Why does this example hang?

Viewed 85

I had this issue for the last 4 years where my feature specs would hang indefinitely, apparently at random. No errors, no failures, nothing. The page goes unresponsive (I am using puma).

I spent such a tremendous amount of time trying to figure out why it was happening that eventually I just stopped using them tests.

Today I figured out what's happening, but can't understand why.

Example that hangs indefinitely (regardless of what Capybara.default_max_wait_time I set):

# spec/features/home_page_spec.rb
require 'spec_helper'
feature "Home page", type: :feature do
  before do
    visit home_path
  end
  it "opens login page on login click" do
    within("#app") do
      find("a.login", match: :first).click
    end
    expect(page).to have_content "Login form"
  end
end

The same example works if visit_home_path is moved from the before hook:

# spec/features/home_page_spec.rb
require 'spec_helper'
feature "Home page", type: :feature do
  it "opens login page on login click" do
    visit home_path
    within("#app") do
      find("a.login", match: :first).click
    end
    expect(page).to have_content "Login form"
  end
end

Why is this happening?

0 Answers
Related