Search code examples
ruby-on-railscapybaraphantomjspoltergeist

Cannot connect PhantomJS and Poltergeist in Rails application


I've followed the instructions on Poltergeist github page but i keep getting an error that my PhantomJS version is wrong.

Specifically, it says:

Could not find an executable 'phantomjs' that matched the requirements '~> 1.8', '>= 1.8.1'. Found versions were {"/home/marko/projects/irs_machine/bin/phantomjs"=>"50"}.

Now, I have downloaded phantomjs v1.8.1 (and later v1.9.2) so the version is correct. This is really driving me crazy. I use Ubuntu 13.04, but I doubt that's the reason.

Googling for the error returns nothing of use.

Any ideas?


Solution

  • I've solved it!

    What I found to be very strange was the fact that the error reported the phantomjs version to be "50" which is impossible.

    I've tracked the error down to the "cliver" gem, a gem that detects versions of installed programs. It does so by regex matching the desired version string to the result of

     {command} -v
    

    Now, when I run phantomjs -v i get "1.8.1", so what was happening? On closer inspection "1.8.1" wasn't all that I was getting back! To be precise, I got this:

     phantomjs -v
     Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading configurations from ~/.fonts.conf is deprecated.
     1.8.1
    

    I had a fontconf error, and sure enough, the first number it contained was "50". Cliver matches against standard output, so it couldn't get a proper version because the system was writing errors out.

    Once I reconfigured the 50-user.conf not to use line 9, the error was gone and poltergeist started working as expected.