ngauthier / capybara-slow_finder_errors

MIT License
212 stars 19 forks source link

[Regression] SlowFinderError not raised on version 0.1.4 #11

Open epidemian opened 7 years ago

epidemian commented 7 years ago

Example app:

require 'sinatra'

get '/' do
  erb '<h1>Hello World</h1>'
end

And the spec:

RSpec.describe "Simple app", js: true, type: :feature do
  it "does something" do
    visit "/"
    expect(page.has_content?("Goodbye World")).to be_falsy
  end
end

(Gist with all the code)

Note that i'm not using expect(page).not_to have_content("Goodbye World") because it seems that Capybara intelligently converts that to the negated matcher.

The expectation is correct though: the page shouldn't have the content "Goodbye world", but Capybara waits a full timeout before succeeding. And this gem fails to notice it 😿

But, if the version 0.1.3 is used instead:

// Gemfile
gem "capybara-slow_finder_errors", "0.1.3"

Then it does raise the SlowFinderError:

$ rspec
127.0.0.1 - - [21/Feb/2017:15:07:15 -0300] "GET / HTTP/1.1" 200 20 0.0337
F

Failures:

  1) Simple app does something
     Failure/Error: expect(page.has_content?("Goodbye World")).to be_falsy

     Capybara::SlowFinderError:
       Timeout reached while running a *waiting* Capybara finder...perhaps you wanted to return immediately? Use a non-waiting Capybara finder. More info: http://blog.codeship.com/faster-rails-tests?utm_source=gem_exception
     # ./spec/simple_app_spec.rb:4:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Capybara::ExpectationNotMet:
     #   expected to find text "Goodbye World" in "Hello World"
     #   ./spec/simple_app_spec.rb:4:in `block (2 levels) in <top (required)>'

Finished in 8.31 seconds (files took 0.74391 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/simple_app_spec.rb:2 # Simple app does something

I think this was a regression introduced in PR #10, which deleted the SlowFinderError and let an Capybara::ElementNotFound error be raised, which seems to be caught by Capybara on these predicate methods.