TypeError when running guard-rspec second pass
agross opened this issue · comments
I recently upgraded to guard-rspec 4.2.9. When guard-rspec detects a modification on my spec files it tries to run but fails:
10:24:39 - ERROR - Guard::RSpec failed to achieve its <run_on_modifications>, exception was:
> [#] TypeError: no implicit conversion from nil to integer
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:40:in `system'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:40:in `block in _run'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:59:in `block in _without_bundler_env'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/bundler-1.6.2/lib/bundler.rb:235:in `block in with_clean_env'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/bundler-1.6.2/lib/bundler.rb:222:in `with_original_env'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/bundler-1.6.2/lib/bundler.rb:228:in `with_clean_env'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:59:in `_without_bundler_env'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:40:in `_run'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb:29:in `run'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec.rb:34:in `block in run_on_modifications'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec.rb:40:in `_throw_if_failed'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec.rb:34:in `run_on_modifications'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-2.6.1/lib/guard/runner.rb:74:in `block in run_supervised_task'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-2.6.1/lib/guard/runner.rb:71:in `catch'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-2.6.1/lib/guard/runner.rb:71:in `run_supervised_task'
> [#] C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-2.6.1/lib/guard/runner.rb:119:in `block in _run_first_task_found'
...
It's always failing when run on Windows. The same guard succeeds on Ubuntu. Using rspec 3.0.0.
@agross Seems like error occurs in Kernel.system(command)
expression. May be guard-rspec
tries to execute a shell command which is not supported on Windows platform. How do you usually run rspec
on Windows?
Kernel.system
has never been causing problems for me. I normally run bundle exec rspec
.
@agross I did not use guard-rspec
on Windows :(. It would be great if you debug the issue and find which command causes error.
- open up
C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb
in an editor - after the line (line 39) with
command = Command.new(paths, options)
insert the following:
STDERR.puts [command, options, paths].inspect
like so:
def _run(all, paths, options)
command = Command.new(paths, options)
STDERR.puts [command, options, paths].inspect
_without_bundler_env { Kernel.system(command) }.tap do |success|
Then tell us what output you get.
After that, run gem pristine guard-rspec
to undo the change.
And you may want to verify the :cmd
and :cli
options passed to guard-rspec in your Guardfile.
First run:
["bundle exec rspec -f progress -r C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec", {:all_on_start=>true, :all_after_pass=>true, :run_all=>{:message=>"Running all specs"}, :failed_mode=>:focus, :spec_paths=>["spec"], :cmd=>"bundle exec rspec", :launchy=>nil, :notification=>true, :message=>"Running all specs"}, ["spec"]]
Second run with a modified file:
["bundle exec rspec -f progress -r C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec/rake/funnel/tasks/msbuild_spec.rb", {:all_on_start=>true, :all_after_pass=>true, :run_all=>{:message=>"Running all specs"}, :failed_mode=>:focus, :spec_paths=>["spec"], :cmd=>"bundle exec rspec", :launchy=>nil, :notification=>true}, ["spec/rake/funnel/tasks/msbuild_spec.rb"]]
The funny thing is I can run all guards without problems >1 times. Here's my Guardfile:
guard 'rspec',
:all_on_start => true,
:all_after_pass => true,
:notification => true,
:cmd => 'bundle exec rspec' do
watch('.rspec') { 'spec' }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
I traced it down to the Coveralls gem. As long as I call Coveralls.wear!
in spec_helper.rb
the second run fails. Reproduction
Do you know how I may detect a Guard environment and disable Coveralls in this case?
@agross I tried to run ENV.keys.select { |k| k =~ /GUARD/ }
and get => ["GUARD_NOTIFIERS", "GUARD_NOTIFY"]
. So you may check ENV['GUARD_NOTIFY']
or something similar...
@agross May be you should report the issue to coveralls community
@agross Also, please, try to run the next code in rails console
:
Kernel.system "bundle exec rspec -f progress -r C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec/rake/funnel/tasks/msbuild_spec.rb"
I think you should see the backtrace of the error
@907th Many thanks for your support!
- I now use
Coveralls.wear! if Coveralls.will_run?
to disable Coveralls outside of Travis. - lemurheavy/coveralls-ruby#50
- Unfortunately, in irb (~ rails console I guess, I don't use Rails) the backtrace doesn't show up. I think Coveralls might alter some global state that is persisted across Guard runs, which is not the case when using irb.
I'll close the issue, doesn't seem to be related to guard-rspec.
Actually, I'm not convinced it's simply a coveralls issue - it might be the trigger, but not the cause.
It blows my mind that system() could be throwing such an exception, so there's something real fishy going on here...
Guard::Rspec::Command inherits from String (see: lib/guard/rspec/command.rb)
Could you try changing the Command class:
- to not inherit from String
- remove the super() call
- implement a
to_s
method (which calls_parts.join(' ')
- and in lib/guard/rspec/runner.rb use:
command = Command.new(paths, options).to_s
Doing so may reveal the cause or the exception (which itself simply may not be properly reported).
@e2 I quickly applied the modifications you suggested. No change in outputs, error messages et al.
I'm facing the same issue, except i'm not using Coveralls. @agross were you able to do any further troubleshooting on your end?
@tobmatth Unfortunately not. The if coveralls.will_run part worked for me.
@tobmatth - you could try a newer version of Ruby (it's worth a shot for multiple reasons).
@e2 Thanks for your suggestion, unfortunately my project requires Postgres which doesn't seem to be compatible with Ruby 2.1 on Windows yet (I'm on 2.0.0p481 currently). Anyway - i don't think this is a Ruby related issue, as i had guard-rspec already up and running within this project.
I will try to dig deeper into this tomorrow...
@tobmatth - if Kernel.system is failing with a type error (what it seems to be), it very much does seem like a Ruby issue (which would also explain why it works on other platforms).
And if that's the case, you should be able to reproduce this in pure ruby.
Just to make sure, you could try to change the line mentioned to:
command = String.new(Command.new(paths, options).to_s)
@e2 I'm able to execute the resulting command in irb using Kernel.system without any Exception:
command = String.new(Command.new(paths, options).to_s)
STDERR.puts command
_without_bundler_env { Kernel.system(command) }.tap do |success|
...
Output:
15:10:35 - INFO - Running: spec/models/content_element_spec.rb
bundle exec rspec -f progress -r C:/Ruby200/lib/ruby/gems/2.0.0/gems/guard-rspec-4.3.1/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec/models/content_element_spec.rb
15:11:00 - ERROR - Guard::RSpec failed to achieve its <run_on_modifications>, exception was:
> [#] TypeError: no implicit conversion from nil to integer
> .........................................
> 41 examples, 0 failures
IRB:
irb(main):001:0> command = "bundle exec rspec -f progress -r C:/Ruby200/lib/ruby/gems/2.0.0/gems/guard-rspec-4.3.1/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec/models/content_element_spec.rb"
irb(main):002:0> Kernel.system command
> .........................................
> 41 examples, 0 failures