sequenceserver icon indicating copy to clipboard operation
sequenceserver copied to clipboard

Is it possible to skip capybara tests if geckodriver is not installed?

Open yeban opened this issue 3 years ago • 9 comments

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.

yeban avatar Apr 19 '22 13:04 yeban

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?

dpavam avatar May 25 '22 15:05 dpavam

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.

yeban avatar May 26 '22 09:05 yeban

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?

ikozakov avatar May 26 '22 09:05 ikozakov

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

yeban avatar May 26 '22 11:05 yeban

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?

dpavam avatar Jun 06 '22 16:06 dpavam

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 avatar Jun 06 '22 18:06 ikozakov

@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?

imagen

dpavam avatar Jun 06 '22 21:06 dpavam

@dpavam yeah i see it now.

so two options here:

  1. 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
  1. Or use system instead of "`" :
def geckodriver_installed?
  system('geckodriver -V')
end

ikozakov avatar Jun 07 '22 07:06 ikozakov

Hi both, thank you very much for your help. I've implemented these changes in #604.

dpavam avatar Jun 07 '22 15:06 dpavam