Is it possible to skip capybara tests if geckodriver is not installed?
Capybara tests fail if geckodriver is not installed. It could be nice if they were simply not run, like treated as pending, if geckodriver is not installed or other dependencies are not met.
Hi @yeban. I gave this one a go and consulted with @ikozakov.
Why is it desirable to skip the tests rather than making sure that geckodriver is installed? If this is not an option, Ivan has suggested using tags and then running something like:
rspec spec --tag ~@gecko_dependent.
This would run all tests except for those tagged. Would that solve the issue?
Installing geckodriver is definitely an option. All capybara tests require geckodriver, so I am not sure how useful tags approach is, and we are only talking capybara tests here.
Probably we could fail (exit) the entire test-run at the very beginning if geckodriver is not installed, saying something like "geckodriver is not installed" (and probably add some info on how to install geckodriver)
Code example:
somewhere.rb
def geckodriver_installed?
# geckodriver 0.31.0
!!`geckodriver -V`.match(/geckodriver \d+.\d+.\d+/)
end
spec_helper.rb (somewhere at the top)
fail("Please install geckodriver before running rspec. Check Readme.md for details.") unless geckodriver_installed?
I was thinking more like:
# spec/spec_helper.rb
RSpec.configure do |config|
config.include DownloadHelpers, type: :feature
# Setup capybara tests.
- config.before :context, type: :feature do
+ config.before :context, type: :feature do |context|
+ context.skip('Install geckodriver first') unless geckodriver_installed?
Capybara.app = SequenceServer
Capybara.server = :webrick
Capybara.default_max_wait_time = 30
Here, geckodriver_installed? is a method that can be defined as in the above comment.
❯ bundle exec rspec spec/capybara_spec.rb
/Users/priyam/wurmlab/sequenceserver/spec/spec_helper.rb:16: warning: already initialized constant SequenceServer::DOTDIR
/Users/priyam/wurmlab/sequenceserver/lib/sequenceserver.rb:14: warning: previous definition of DOTDIR was here
********************
Pending: (Failures listed here are expected and do not affect your suite's status)
1) a browser sorts databases alphabetically
# Install geckodriver first
# ./spec/capybara_spec.rb:6
2) a browser properly controls blast button
# Install geckodriver first
# ./spec/capybara_spec.rb:17
3) a browser properly controls interaction with database listing
# Install geckodriver first
# ./spec/capybara_spec.rb:27
...
Haven't tested running all tests
Hi both, I tried both approaches but I get this message and failures for all capyabara tests:
Failure/Error: !!'geckodriver -V'.match(/geckodriver \d+.\d+.\d+/) Errno::ENOENT: No such file or directory - geckodriver
Where should geckodriver_installed? be placed in that case?
Can you please send me a screenshot of your code? (the method works, but it looks like it fails inside)
Any place in spec_helper.rb should be fine for this method to work.
@ikozakov this happens when geckodriver is not installed and I run: rspec spec/capybara_spec.rb or rspec spec
In spec_helper.rb:
Line 8:
def geckodriver_installed?
# geckodriver 0.31.0
!!'geckodriver -V'.match(/geckodriver \d+.\d+.\d+/)
end
Line 13:
fail("Please install geckodriver before running rspec. Check the firefox-geckodriver documentation or try: sudo apt install firefox-geckodriver.") unless geckodriver_installed?

@dpavam yeah i see it now.
so two options here:
- change the method to something like this:
def geckodriver_installed?
# geckodriver 0.31.0
!!`geckodriver -V || echo 'not installed'`.match(/geckodriver \d+.\d+.\d+/)
end
- Or use
systeminstead of "`" :
def geckodriver_installed?
system('geckodriver -V')
end
Hi both, thank you very much for your help. I've implemented these changes in #604.