guard / guard-spork

Guard::Spork automatically manage Spork DRb servers
https://rubygems.org/gems/guard-spork
MIT License
296 stars 58 forks source link

ERROR: Guard::CoffeeScript guard failed to achieve its <run_on_change> command: undefined method `success?' for nil:NilClass #19

Closed flippyhead closed 13 years ago

flippyhead commented 13 years ago

Getting the error:

ERROR: Guard::CoffeeScript guard failed to achieve its command: undefined method `success?' for nil:NilClass

When using guard-spork along with guard-coffeescript. Not sure if this is related to the execjs issue. Passing the -d option to guard does not produce any more useful information so not sure how to further debug..

thibaudgg commented 13 years ago

Without using guard-spork, you don't get this error? Can you please give your, Guardfile, Gemfile & spec_helper.rb.

@netzpirat do you know if it's more related to guard-coffeescript than guard-spork ?

thibaudgg commented 13 years ago

any news about this one?

termhare commented 13 years ago

Grouping them into frontend and backend solves the problem for me:

group 'backend' do
  guard 'bundler' do
    watch('Gemfile')
  end

  guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.+\.rb$})
    watch(%r{^config/initializers/.+\.rb$})
    watch('spec/spec_helper.rb')
  end

  guard 'rspec', :version => 2 do
    watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
    watch('spec/spec_helper.rb')  { "spec" }

    # Rails example
    watch(%r{^spec/(.+)_spec\.rb$})                     { |m| "spec/#{m[1]}_spec.rb" }
    #watch(%r{^spec/factories/(.+)_factory\.rb$})        { |m| "spec" }
    watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
    watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
    watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
    watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
    watch('spec/spec_helper.rb')                        { "spec" }
    watch('config/routes.rb')                           { "spec/routing" }
    watch('app/controllers/application_controller.rb')  { "spec/controllers" }
    # Capybara request specs
    watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
  end

  guard 'cucumber' do
    watch(%r{^features/.+\.feature$})
    watch(%r{^features/support/.+$})          { 'features' }
    watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
  end
end

group 'frontend' do
  guard 'coffeescript', :input => 'app/assets/javascripts', :output => 'public/javascripts'
  guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'

  guard 'jasmine-headless-webkit' do
    watch(%r{^app/assets/javascripts/(.*)\..*})
    watch(%r{^spec/javascripts/(.*)\..*})
  end

  guard 'jammit' do
    watch(%r{^public/javascripts/(.*)\.js})
    watch(%r{^public/stylesheets/(.*)\.css})
  end
end
thibaudgg commented 13 years ago

Ok fine, I'm glad you have found a way to solve this issue.

bhavinkamani commented 13 years ago

I am facing the same issue. I am using this on rails 3.1. Error does not occur when I comment out guard-spork configuration from Guardfile. It occurs randomly (infact most of the time) when I group the code as mentioned above. After occurance of the error guard-coffeescript stops working. I need to restart guard. Let me know if you need any other details that can help you debug the issue.

bhavinkamani commented 13 years ago

Digging further into the issue, it appears that there is some sort of conflict that happens between ExecJS and guard:spork. I am not able to pinpoint specific nature of the conflict or exact code location as it happens pretty randomly. After every 1-2 successful coffee-script generation, guard throws this above error and stops responding.

Is it anything to do with Issue #18?

Here are my files

Guardfile


  guard 'ego' do
    watch('Guardfile')
  end

  guard 'pow' do
    watch('.powrc')
    watch('.powenv')
    watch('.rvmrc')
    watch('Gemfile')
    watch('Gemfile.lock')
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.*\.rb$})
    watch(%r{^config/initializers/.*\.rb$})
  end

  guard 'spork', :rspec_env => {'RAILS_ENV' => 'test'} do
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.+\.rb$})
    watch(%r{^config/initializers/.+\.rb$})
    watch('spec/spec_helper.rb')
  end

  guard 'bundler' do
    watch('Gemfile')
    # Uncomment next line if Gemfile contain `gemspec' command
    # watch(/^.+\.gemspec/)
  end

  guard 'rspec', :version => 2, :cli => "--drb" do
    # Rails example
    watch('spec/spec_helper.rb') { "spec" }
    watch('config/routes.rb') { "spec/routing" }
    watch('app/controllers/application_controller.rb') { "spec/controllers" }
    watch(%r{^spec/.+_spec\.rb})
    watch(%r{^app/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
    watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
    watch(%r{^app/controllers/(.+)_(controller)\.rb}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  end

  guard 'coffeescript', :input => 'app/assets/javascripts', :output => 'public/javascripts/compiled'

  guard 'coffeescript', :input => 'spec/assets/javascripts', :output => 'spec/javascripts'

Gemfile

source 'http://rubygems.org'

gem 'rails', :path => '../../../github/rails'

gem 'pg'

# Asset template engines
gem 'coffee-script'
gem 'jquery-rails'
gem 'haml'
gem 'haml-rails'
gem 'json'
gem 'simple_form'

gem 'unicorn'
gem 'capistrano'
gem 'chronic'
gem 'expanded_date'
gem 'ruby-debug19', :require => 'ruby-debug'

group :development, :test do
  gem 'wirble'
  gem 'hirb'
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem "shoulda-matchers"
  gem 'simplecov', '>= 0.4.0', :require => false, :group => :test
  gem 'factory_girl_rails'
  gem 'factory_girl_generator'
  gem 'growl'
  gem 'guard'
  gem 'guard-ego'
  gem 'guard-pow'
  gem 'guard-spork'
  gem 'guard-coffeescript'
  gem 'guard-bundler'
  gem 'guard-jstd'
  gem 'guard-rspec'
  gem 'rb-fsevent'
  gem 'spork', '>= 0.9.0.rc'
  gem 'forgery'
  gem 'jasmine'
end

spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    config.mock_with :rspec

    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    config.use_transactional_fixtures = true
  end

end

Spork.each_run do
  require 'simplecov'
  SimpleCov.start "rails"

end
okonet commented 12 years ago

I'm getting this error:

ERROR: Guard::CoffeeScript failed to achieve its , exception was: NoMethodError: undefined method `each' for nil:NilClass

after Coffeescript Guard failed to produce a JS file:

for example on syntax error: ERROR: ExecJS engine error: SyntaxError: reserved word "var" on line 12

but actually almost on any syntax error so above is just a particular example.

okonet commented 12 years ago

Using 1.9.3 without Rails project.

source :rubygems

group :development do
  gem 'rake'
  gem 'sinatra'
  gem 'r18n-core'
  gem 'json'
  gem 'compass'
  gem 'coffee-script'
  gem 'oily_png' # C extension for faster PNG workflow
  gem 'padrino-helpers'
  gem 'jammit-sinatra', :git => 'git://github.com/joesteele/jammit-sinatra.git' # custom repo because of https://github.com/railsjedi/jammit-sinatra/pull/1
  gem 'jasmine-headless-webkit'

  # setup guard
  gem "guard"
  gem 'growl'
  gem "rb-fsevent"

  gem "guard"
  gem "guard-livereload"
  gem "guard-coffeescript"
  gem "guard-compass"
  gem 'guard-jammit'
  gem 'guard-jasmine-headless-webkit'
  gem 'yui-compressor', :git => 'git://github.com/andrewgarner/ruby-yui-compressor.git', :ref => '6d1cbe68e1'
end

group :deployment do
  gem "revup", "~> 0.2.0"
end
require 'guard/guard'
require 'json'
require './app/app_helpers'

module ::Guard
  class ApplicationScss < ::Guard::Guard
    include AppHelpers

    def run_all
      generate_app_and_view_scss
    end

    def run_on_change(paths)
      generate_app_and_view_scss
    end
  end
end

module ::Guard
  class ApplicationConfig < ::Guard::Guard
    include AppHelpers

    def run_all
      generate_configs
      generate_locales
    end

    def run_on_change(paths)
      paths.each do |path|
        puts "Converting yml to js for #{path}"
        generate_config_by_path(path)
      end
    end
  end
end

group "development" do
  guard "ApplicationConfig" do
    watch(%r{^app/config/.+\.yml})
    watch(%r{^app/i18n/.+\.yml})
  end

  guard "ApplicationScss" do
    watch("app/stylesheets/application.scss.erb")
  end

  guard 'coffeescript', :input => 'app', :output => 'public/javascripts/app', :cli => ''
  guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'

  guard 'compass' do
    watch(/app\/stylesheets\/(.*)\.s[ac]ss/)
  end

  spec_location = "spec/coffeescripts/%s_spec"
  guard 'jasmine-headless-webkit' do
    # watch(%r{^app/templates/jst/.*\.jst$})
    # watch(%r{^public/javascripts/app/(.*)\.js$}) { |m| newest_js_file(spec_location % m[1]) }
    # watch(%r{^app/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
    watch(%r{^spec/coffeescripts/(.*)_spec\..*}) { |m| newest_js_file(spec_location % m[1]) }
    watch(%r{^app/(.*)\..*}) { |m| newest_js_file(spec_location % m[1]) }
  end

  guard 'livereload', :apply_js_live => false do
    watch(%r{^public/.+\.js})
    watch(%r{^public/.+\.css})
  end
end

group "production" do
  guard 'jammit' do
    watch(%r{^public/.+\.js})
    watch(%r{^public/.+\.css})
  end
end
thibaudgg commented 12 years ago

@okonet it seems to be more an error with guard-coffeescript rather than guard-spork no?

okonet commented 12 years ago

Ouch I was confused by title of that case. Will file it under guard-coffeescript.