I have a problem when running rspec --drb within guard with spork: It's look like guard stops to run rspec commands and track changes after any syntax error in ruby files(project or spec files).
When I run rspec from guard without spork(and without--drb) it's working fine. Also spork+rspec works fine then running without guard
The error:
18:18:19 - INFO - Run all
18:18:20 - INFO - Running all specs
Running tests with args ["--color", "--failure-exit-code", "2", "--format", "documentation", "--format", "Guard::RSpecFormatter", "--require", "spec_helper", "--require", "/home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec_formatter.rb", "spec"]...
Exception encountered: #<SyntaxError: /media/sf_win-sites/Intelinets/happiness/app/models/product.rb:3: syntax error, unexpected tIDENTIFIER, expecting keyword_end
1validates :price , numericality: true #{greater_than: 0}
^>
backtrace:
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `block in require'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:247:in `require'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:348:in `require_or_load'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:480:in `load_missing_constant'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:180:in `const_missing'
/media/sf_win-sites/Intelinets/happiness/spec/models/product_spec.rb:2:in `<top (required)>'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `load'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `block in load'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.9/lib/active_support/dependencies.rb:241:in `load'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
/home/sphinx/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/test_framework/rspec.rb:12:in `run_tests'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/run_strategy/forking.rb:13:in `block in run'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/forker.rb:21:in `block in initialize'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/forker.rb:18:in `fork'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/forker.rb:18:in `initialize'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/run_strategy/forking.rb:9:in `new'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/run_strategy/forking.rb:9:in `run'
/home/sphinx/.rvm/gems/ruby-2.1.5/bundler/gems/spork-224df492657e/lib/spork/server.rb:49:in `run'
/home/sphinx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/drb/drb.rb:1588:in `perform_without_block'
/home/sphinx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/drb/drb.rb:1548:in `perform'
/home/sphinx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/home/sphinx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/drb/drb.rb:1622:in `loop'
/home/sphinx/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/drb/drb.rb:1622:in `block in main_loop'
Done.
18:18:22 - ERROR - Guard::RSpec failed to achieve its <run_all>, exception was:
> [#ede981094807] Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/rspec_guard_result
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/results.rb:11:in `readlines'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/results.rb:11:in `initialize'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/rspec_process.rb:46:in `new'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/rspec_process.rb:46:in `_read_results'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/rspec_process.rb:17:in `initialize'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/runner.rb:68:in `new'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/runner.rb:68:in `_really_run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/runner.rb:57:in `_run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec/runner.rb:34:in `run_all'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec.rb:33:in `block in run_all'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec.rb:48:in `_throw_if_failed'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-rspec-4.6.4/lib/guard/rspec.rb:33:in `run_all'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:82:in `block in _supervise'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:79:in `catch'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:79:in `_supervise'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:22:in `block (3 levels) in run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:119:in `block (2 levels) in _run_group_plugins'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:117:in `each'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:117:in `block in _run_group_plugins'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:116:in `catch'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:116:in `_run_group_plugins'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:21:in `block (2 levels) in run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:20:in `each'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:20:in `block in run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/lumberjack-1.0.10/lib/lumberjack.rb:32:in `unit_of_work'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/runner.rb:18:in `run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/commander.rb:82:in `run_all'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/internals/queue.rb:42:in `block in _run_actions'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/internals/queue.rb:37:in `each'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/internals/queue.rb:37:in `_run_actions'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/internals/queue.rb:21:in `process'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/commander.rb:43:in `start'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/cli/environments/valid.rb:16:in `start_guard'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/cli.rb:122:in `start'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/aruba_adapter.rb:32:in `execute'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/lib/guard/aruba_adapter.rb:19:in `execute!'
> [#ede981094807] /home/sphinx/.rvm/gems/ruby-2.1.5/gems/guard-2.13.0/bin/_guard-core:11:in `<main>'
18:18:22 - INFO - Guard::RSpec has just been fired
gemfile:
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'capybara'
gem 'guard-rspec', require: false
gem 'sqlite3'
# gem 'guard-livereload'
gem 'spork', github: 'sporkrb/spork'
gem 'spork-rails', github: 'sporkrb/spork-rails' # rubygems version not rails 4 compatible
gem 'guard-spork', :github => 'guard/guard-spork'
# gem 'childprocess'
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'minitest'
gem 'shoulda-matchers', '2.5.0'
end
spec_helper:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'
require "shoulda/matchers"
ActiveRecord::Migration.maintain_test_schema!
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
end
Spork.each_run do
end
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
guardfile:
guard :rspec, :cmd => "rspec --drb" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issues for suggestions and improvements
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end
guard :spork, :rspec_env => { 'RAILS_ENV' => 'test' }, test_unit: false do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
# watch('test/test_helper.rb') { :test_unit }
# watch(%r{features/support/}) { :cucumber }
end
.rspec:
--color
--require spec_helper
--format documentation
Personally, I'd recommend switching from spork to spring or zeus.
But that's unrelated to the issue here.
First, it's best to open issues on the GitHub page of guard-rspec. (You'll likely get a faster response and you can track when a fix is officially released).
The problem is really here:
For some reason
guard-rspeccan't open it's results file.I'm guessing it's because when you run rspec with
--drb, the failures aren't reported to Guard-RSpec (through theGuard::RSpecFormatterclass).So I'm not sure if rspec --drb can be made to work here. You can try a newer version of RSpec to see if it helps.
If you can setup a small repo reproducing the problem and open an issue in https://github.com/guard/guard-rspec/issues/new , I can take a look.