Search code examples
ruby-on-railsjasmineguardphantomjs

Can't open guard-jasmine.coffee, No response from the Jasmine runner


When I try to run guard-jasmine in my guard set up or in the independent guard-jasmine command I get this error

Guard::Jasmine starts thin test server on port 8888 in test environment.
Waiting for Jasmine test runner at http://example.com:8888/
Run Jasmine suite spec/javascripts/credit_card_spec.js
Run Jasmine suite at http://example.com:8888/?spec=CreditCard
Can't open '/home/yuvilio/.rvm/gems/ruby-1.9.3-p194@agilerails/bundler/gems/guard-jasmine-0fd614d12263/lib/guard/jasmine/phantomjs/guard-jasmine.coffee'
ERROR: No response from the Jasmine runner!

Strangely, the 'guard-jasmine.coffee' file is indeed there and seems fine.

My Gemfile includes:

group :test, :development do
  #...
  gem 'guard-jasmine', :git => "https://github.com/netzpirat/guard-jasmine.git", :branch => 'master'
  gem 'jasminerice', :git => "https://github.com/bradphelan/jasminerice.git", :branch => 'master'
  gem 'jasmine'
end

my Guardfile includes:

guard 'jasmine', :all_on_start => false, :server => :thin, :port => 8888,  :jasmine_url => 'http://localhost:8888/', :server_env => :test do
  watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$})         { "spec/javascripts" }
  watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
  watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)$})  { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
end

When I run rake jasmine and browse to that http://example.com:8888/?spec=CreditCard test, it shows up fine (the test currently fails as expected). Any idea what is causing the guard

Postscript:

This turned out to be a phantomjs issue. @netzpirat correctly diagnosed it in a comment in his answer below. I was using Ubuntu, whose latest phantomjs was version 1.4. The "Can't open" error was happening there (related to this bug perhaps?). To resolve, I found a PPA that had 1.5 and installed it from there (it's also available directly for more architectures here ). That fixed it.


Solution

  • When you're using Jasminerice to serve the Jasmine specs through the asset pipeline, the URL is http://localhost:8888/jasmine by default. Since this is also the guard-jasmine default, you can simply skip the option (also port 8888 is default):

    guard 'jasmine', :all_on_start => false, :server => :thin, :server_env => :test do
      watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$})         { "spec/javascripts" }
      watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
      watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)$})  { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
    end
    

    The reason why I have chosen development as the default for :server_env is, that you'll see the real file name where an error has occurred. I recommend to have it set to development for local development and test on the CI server.