Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when running guard-rspec second pass #267

Closed
agross opened this issue Jun 3, 2014 · 18 comments
Closed

TypeError when running guard-rspec second pass #267

agross opened this issue Jun 3, 2014 · 18 comments

Comments

@agross
Copy link

agross commented Jun 3, 2014

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.

@907th
Copy link
Contributor

907th commented Jun 3, 2014

@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?

@agross
Copy link
Author

agross commented Jun 3, 2014

Kernel.system has never been causing problems for me. I normally run bundle exec rspec.

@907th
Copy link
Contributor

907th commented Jun 3, 2014

@agross I did not use guard-rspec on Windows :(. It would be great if you debug the issue and find which command causes error.

@e2
Copy link
Contributor

e2 commented Jun 3, 2014

@agross

  1. open up C:/Ruby/lib/ruby/gems/2.0.0/gems/guard-rspec-4.2.9/lib/guard/rspec/runner.rb in an editor
  2. 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.

@agross
Copy link
Author

agross commented Jun 3, 2014

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?

@907th
Copy link
Contributor

907th commented Jun 3, 2014

@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...

@907th
Copy link
Contributor

907th commented Jun 3, 2014

@agross May be you should report the issue to coveralls community

@907th
Copy link
Contributor

907th commented Jun 3, 2014

@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

@agross
Copy link
Author

agross commented Jun 3, 2014

@907th Many thanks for your support!

@agross
Copy link
Author

agross commented Jun 3, 2014

I'll close the issue, doesn't seem to be related to guard-rspec.

@agross agross closed this as completed Jun 3, 2014
@e2
Copy link
Contributor

e2 commented Jun 3, 2014

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).

@agross
Copy link
Author

agross commented Jun 3, 2014

@e2 I quickly applied the modifications you suggested. No change in outputs, error messages et al.

@tobmatth
Copy link

tobmatth commented Oct 8, 2014

I'm facing the same issue, except i'm not using Coveralls. @agross were you able to do any further troubleshooting on your end?

@agross
Copy link
Author

agross commented Oct 8, 2014

@tobmatth Unfortunately not. The if coveralls.will_run part worked for me.

@e2
Copy link
Contributor

e2 commented Oct 8, 2014

@tobmatth - you could try a newer version of Ruby (it's worth a shot for multiple reasons).

@tobmatth
Copy link

tobmatth commented Oct 8, 2014

@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...

@e2
Copy link
Contributor

e2 commented Oct 8, 2014

@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)

@tobmatth
Copy link

tobmatth commented Oct 8, 2014

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants