Reputation: 362
So i'm trying to use guard rspec just for ruby, and not for rails. The test runs fine but the only problem is that it only looks for the spec.rb file, and doesn't look for the actual file. So I have a failed arabic_to_roman.rb and arabic_to_roman_spec.rb. the Guardfile is installed under the directory roman_numerals_kata. It only looks for the _spec.rb file and not the arabic_to_roman.rb. here is what the Guardfile looks like
1 # A sample Guardfile
2 # More info at https://github.com/guard/guard#readme
3
4 guard 'rspec' do
5 watch(%r{^spec/.+_spec\.rb$})
6 watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7 watch('spec/spec_helper.rb') { "spec" }
8
9 # Rails example
10 watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11 watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}# {m[2]}_spec.rb" }
12 watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/# {m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13 watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14 watch('config/routes.rb') { "spec/routing" }
15 watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
17 # Capybara features specs
18 watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
20 # Turnip features and steps
21 watch(%r{^spec/acceptance/(.+)\.feature$})
22 watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23 end
24
Upvotes: 0
Views: 125
Reputation: 161
What is the structure of your directory?
Based on this config, Guard looks for any ruby files in the lib directory and will execute the matching test that is nested inside spec/lib/. Those details are in this line of the guardfile: watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
.
Using this Guardfile (which matches my standard project layout) you should have the following folder layout:
BASE_DIR
├── Guardfile
├── lib
│ ├── README
│ └── arabic_to_roman.rb
├── spec
│ ├── lib
│ │ └── arabic_to_roman_spec.rb
│ └── spec_helper.rb
The alternative, if not wishing to conform to standard folder layout is to modify the Guardfile like this
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
Notice that the second watch
command is looking for it in the basedir rather than in lib/*
Hope this helps :)
Upvotes: 2