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

Doesn't watch lib folder, only works with spec folder #393

Open
marko-avlijas opened this issue Jan 10, 2017 · 3 comments
Open

Doesn't watch lib folder, only works with spec folder #393

marko-avlijas opened this issue Jan 10, 2017 · 3 comments

Comments

@marko-avlijas
Copy link

marko-avlijas commented Jan 10, 2017

I have installed & run bundle exec guard init rspec and it seems Guardfile is set wrong because it doesn't catch changes in my lib folder.

I also get an exception when I save a file in spec folder, even though tests run.

16:37:13 - DEBUG - Guard::RSpec: RSpec command bundle exec rspec -f progress -r /home/marko/.gem/ruby/2.3.1/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb -f Guard::RSpecFormatter --failure-exit-code 2  spec/front_page_spec.rb exited with: 2
16:37:13 - DEBUG - Command execution: notify-send RSpec results 29 examples, 8 failures in 0.0656 seconds -t 3000 -h int:transient:1 -i /home/marko/.gem/ruby/2.3.1/gems/notiffany-0.1.1/images/failed.png -u normal

16:37:13 - DEBUG - Start interactor

I have used default Guardfile

guard :rspec, cmd: "bundle exec rspec" 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)
end

How can I inspect what is rspec.spec_files?

How to make it catch my lib folder?

When I run guard and save file in spec folder I get:

Error: there was a problem executing system command: 
16:47:33 - DEBUG - Interactor was stopped or killed
16:47:33 - DEBUG - Hook :run_on_modifications_begin executed for Guard::RSpec
16:47:33 - DEBUG - Hook :run_on_modifications_end executed for Guard::RSpec
16:47:33 - DEBUG - Start interactor
[1] guard(main)> 
@marko-avlijas marko-avlijas changed the title Doesn't watch lib folder, expections in spec folder Doesn't watch lib folder, only works with spec folder Jan 11, 2017
@marko-avlijas
Copy link
Author

marko-avlijas commented Jan 12, 2017

I finally figured out what this thing was. I had my lib code in two modules and I wanted to test only one so I didn't bother creating module folder in specs.

I've had this:
lib/gallery/file1.rb
lib/gallery/file2.rb
lib/legacy/no_tests1.rb
lib/legacy/no_tests2.rb

spec/file1.rb
spec/file2.rb

I thought guard will figure out matching spec for file if filename is unique.

It got fixed when I moved all my spec files in to spec/lib/gallery/

Please add this to documentation because I lost 2 days and lots of nerves. Stackoverflow was useless as well. All that could have been avoided if documentation mentioned that spec folder structure must match lib folder structure, which is a pretty unique requirement.

Debug output was also very useless. Interactor stopped or got an exception?
Why was it stopped? What was exception message?

Message like this would have saved me 2 days:

Interactor started
Spec for lib/gallery/file1.rb not found (in spec/lib/gallery/file1_spec.rb)
Interactor stopped

@dcrockwell
Copy link

dcrockwell commented Sep 7, 2020

It's been about 4 years. Any updates on this? Major gotcha for new guard-rspec users that costs a lot of time.

Nevermind. the -d debug option provides all the info needed.

@dcrockwell
Copy link

I solved this with the following guard watch command, which watches for files in folders under lib, then runs the corresponding specs in a folder of the same name:

watch(/^lib\/(.*)\/.*\.rb/) { |m| "spec/#{m[1]}" }

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

2 participants