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

Guard is running wrong specs when used with spring #272

Closed
ibrahima opened this issue Jun 29, 2014 · 12 comments
Closed

Guard is running wrong specs when used with spring #272

ibrahima opened this issue Jun 29, 2014 · 12 comments

Comments

@ibrahima
Copy link

I'm not sure if this is a guard-rspec issue, a spring issue, or a guard issue, but I've got a (private) Rails 3 project that I'm using Spring and Rspec3 with (well, I upgraded to these in an effort to modernize the project a bit and eventually move to Rails 4). When I use the default Guardfile it works fine without Spring, but when I use spring like

guard :rspec, all_after_pass: false, cmd: 'spring rspec spec -f doc' do

and then edit a file, it doesn't re-run the specs that are relevant to that file, it instead runs a fixed subset of unrelated specs every time I modify files. This defeats the purpose of Spring, needless to say. Any ideas on how I can figure out what's going on or try to fix it? It seems like if this happened to everyone no one would use spring with guard-rspec but it seems like it works for some people. Apologies if this is not the proper place for this kind of issue.

Relevant gem versions:

guard-rspec (4.2.10)
rspec 3.0.0
rspec-core 3.0.2
rspec-rails 3.0.1
guard 2.6.1

Platform is Linux 3.13 on Ubuntu 14.04.

@e2
Copy link
Contributor

e2 commented Jun 29, 2014

It's probably best to poke around a little to figure out what exactly you're expecting and what you're getting:

  1. Run Guard with the '-d' option and check if it's responding to the right changes (Guard-rspec should say: "Running: " with the files changed).
  2. If that doesn't help, temporarily add a debug statement in runner.rb (in guard-rspec):
      def _run(all, paths, options)
        command = Command.new(paths, options)
        STDERR.puts "Running Rspec: #{command.inspect}"
        _without_bundler_env { Kernel.system(command) }.tap do |success|

Running that command should reproduce the same problem outside guard, which could help work out where the problem is.

That's because many things can influence how everything behaves, so it's best to first work out how Rspec is actually invoked in your case.

Personally I use zeus instead of spring - but everything should work fine regardless, so it's good you're bringing this up.

@ibrahima
Copy link
Author

Yeah, so it's just listing the same set of files regardless of what file I modify, i.e. I modify user_spec.rb and instead I get this:

13:30:15 - INFO - Running: ./spec/mailers/user_mailer_spec.rb:8 ./spec/models/assignment_spec.rb:43 ./spec/models/assignment_spec.rb:48 ./spec/models/assignment_spec.rb:52 ./spec/models/assignment_spec.rb:67 ./spec/models/assignment_spec.rb:71 ./spec/models/assignment_spec.rb:75 ./spec/models/course_spec.rb:88 ./spec/models/free_response_question_spec.rb:34 ./spec/models/free_response_question_spec.rb:38 ./spec/models/free_response_question_spec.rb:42
Run options: include {:locations=>{"./spec/mailers/user_mailer_spec.rb"=>[8], "./spec/models/assignment_spec.rb"=>[43, 48, 52, 67, 71, 75], "./spec/models/course_spec.rb"=>[88], "./spec/models/free_response_question_spec.rb"=>[34, 38, 42]}}

When running without spring it works fine, just re-runs user_spec.rb. Adding the debug statement above also shows the same files being modified:

`Running Rspec: "spring rspec spec -f doc -r /home/ibrahim/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.10/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 ./spec/mailers/user_mailer_spec.rb:8 ./spec/models/assignment_spec.rb:43 ./spec/models/assignment_spec.rb:48 ./spec/models/assignment_spec.rb:52 ./spec/models/assignment_spec.rb:67 ./spec/models/assignment_spec.rb:71 ./spec/models/assignment_spec.rb:75 ./spec/models/course_spec.rb:88 ./spec/models/free_response_question_spec.rb:34 ./spec/models/free_response_question_spec.rb:38 ./spec/models/free_response_question_spec.rb:42"

So, could it be a bug in guard?

@ibrahima
Copy link
Author

Hmm, I've narrowed it down a bit: Looks like when run(paths) is called, the path is correct, and somehow the inspector is getting confused. I inserted a debug statement above this line and the paths argument is the file that was modified only (which makes sense).

https://github.com/guard/guard-rspec/blob/master/lib/guard/rspec/runner.rb#L25

And then after that it prints out the incorrect list of paths.

@e2
Copy link
Contributor

e2 commented Jun 29, 2014

Could you try setting a inspector specifically in the Guardfile, such as failed_mode: :none (https://github.com/guard/guard-rspec#list-of-available-options)?

The README says :none is the default, whereas it seems to be :focus by default, but in your case it seems to be :keep or :focus.

@ibrahima
Copy link
Author

Ah yeah, it seems to be the FocusedInspector (I printed out inspector.class). I tried adding failed_mode: :none, and it re-ran everything. It said

15:51:56 - DEBUG - Inspector is: Guard::RSpec::Inspectors::SimpleInspector
15:51:56 - DEBUG - Guard::Rspec Inspector says: ["spec/models/user_spec.rb"]
15:51:56 - INFO - Running: spec/models/user_spec.rb
Running Rspec: "spring rspec spec -f doc -r /home/ibrahim/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.10/lib/guard/rspec/formatter.rb -f Guard::RSpec::Formatter --failure-exit-code 2 spec/models/user_spec.rb"
No DRb server is running. Running in local process instead ...
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

and then proceeds to run all specs.

@e2
Copy link
Contributor

e2 commented Jun 29, 2014

Either way, guard-rspec needs better logging/debugging - I should get to fixing that at some point...

@e2
Copy link
Contributor

e2 commented Jun 29, 2014

Thanks for reporting this and taking the time to dig in!

@ibrahima
Copy link
Author

Aha! I figured out the solution for my specific case. I had command line specified as

guard :rspec, all_after_pass: false, cmd: 'spring rspec spec -f doc' do

because somewhere on StackOverflow I found a post that said specifying the spec directory fixed some bug for him. But then, I realized just now that this means I'm probably specifying the path twice so one of them is not being used, so I changed it to remove spec from the command line like so:

guard :rspec, all_after_pass: false, cmd: 'spring rspec -f doc', failed_mode: :none do

and it works as expected!

So, is the bug just that the default failed_mode is set incorrectly somehow, perhaps when you specify a custom cmd? It didn't do this when I didn't specify the cmd to use spring.

I'll try removing both options and see what happens. Somehow it's a lot slower with the debug option when running without spring.

Thank you for helping me out! I just didn't know where to look but your guidance was enough to help me figure this out.

@ibrahima
Copy link
Author

Hmm, now I'm confused, when I removed the cmd option (i.e. not using spring) I still see

16:17:22 - DEBUG - Options: {:all_on_start=>false, :all_after_pass=>false, :run_all=>{:message=>"Running all specs"}, :failed_mode=>:focus, :spec_paths=>["spec"], :cmd=>"rspec", :launchy=>nil, :notification=>true}

But I swear it worked normally one time when I was not using spring.

Oh well, I guess the important part is that I know to change failed_mode to :none.

@ibrahima
Copy link
Author

Ah, looks like 4.2.10 does not include 802edda

That explains a lot!

@907th
Copy link
Contributor

907th commented Jun 30, 2014

@ibrahima Yes, it's not released yet =\

@e2
Copy link
Contributor

e2 commented Jun 12, 2015

I'm closing this, because it seems outdated (given the releases that happened since).

If not, please open a new issue if need.

@e2 e2 closed this as completed Jun 12, 2015
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

3 participants