Closed zmoazeni closed 5 years ago
Hey Zach,
Thanks for the ideas! I also see you joined the fun on the capybara issue :smile:.
This gem is a quick packaging of the audit script I used in conjunction with the blog post on Codeship's blog. I thought it would be nice to be able to include it when you want to do an audit. I recognized the same problem you did: it doesn't make sense while you're doing TDD.
IMO these are our options:
require: false
in Gemfile
) for development. Or just include weekly or monthly as an auditCI=true
. So, we can keep the gem all the time and then require: false
in Gemfile
but require 'capybara-slow_finder_errors' if ENV['CI']
in our spec_helper
. We could document this pattern, but I know it won't work for all teams.Right on. For 2) the code snippet above includes the backtrace without worrying about an explicit raise/catch. But it does include a slew of other backtrace junk along with it.
I considered 3) but thought it would make legitimate CI failures hard to read. (We use CircleCI but they have offer the same variable).
I'm fine with sticking with 1). I just wanted to bring it up in case this was news to you. I can submit a PR to add a blurb to the readme if you want to keep this as a separate optimization step.
The capybara codebase is rather hard for me to grok, but I have a suspicion doing anything more clever than 2) will cause this simple monkey patch to get more complicated and harder to maintain.
Ah sorry missed your backtrace stuff in 2. Yeah my intention is for this to be a canary, nothing more. I think just plugging it in for auditing is the best. If someone wants to use it in a particular way they should be able to code it themselves (like 3).
Ideally the best solution would be to change capybara's behavior to consider a timeout a failure, but that's not gonna happen.
One thing we could do is wrap the SlowFinder exception around the element not found exception so that while developing you get to see both.
Ideally the best solution would be to change capybara's behavior to consider a timeout a failure, but that's not gonna happen.
Totally agree.
@ngauthier I'll be going with your option 3 above, but it would be very helpful to add that list to the Readme.
@ngauthier Can you clarify the require syntax for option 3? Requiring slow-finder this way...
require 'capybara-slow_finder_errors' if ENV['CI'].present?
...yields a load error:
~/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- capybara-slow_finder_errors (LoadError)
@ivanoblomov I'm guessing you still need to add it to your Gemfile?
@ngauthier we added it as suggested:
group :test do gem 'capybara-slow_finder_errors', '0.1.2', require: false .. end
Not sure why it doesn't resolve.
ah, sorry the require line is capybara/slow_finder_errors
.
Thanks @ngauthier, that did the trick.
Hi there. I really appreciate the effort you put into debugging and sharing these optimizations. My team enabled the gem for a week and then had to disable it (with an optional enable).
The gem works great. Perhaps too good :smile:. The problem was the gem's error message got in our way while we were debugging a failing test. The
SlowFinderError
would obscure the reason why a test failed. Here is a concrete example so you can see it for yourself:Here is the output with and without slow_finder_errors:
As you can see, slow_finder_errors is doing it's job, but it's also obscuring the real reason for the test failure. It gives you a line number, which is nice, but
expected to find css "#bar" but there were no matches
is very helpful.Now this will only happen with capybara drivers that wait, like poltergeist or capybara-webkit. The default rack_test will fail immediately and consequently not trigger the
SlowFinderError
.My team resorted to having slow_finder_errors opt-in, so that we'd run it once we know we have a green suite as a separate optimization step. We can keep doing that, but it's a bummer to not just have this run all the time.
I toyed with just manually printing the warning with the backtrace instead of raising an error:
Which changes the semantics so that it's more informative than fail-fast:
Any thoughts? Should we continue to make this opt-in? Would you welcome a PR to change the gem to output warning information instead of failing fast with an error? Is there a third option I'm missing altogether?
Thanks for your consideration and your hard work!