Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newly generated Guardfile is empty

Tags:

ruby

rspec

guard

I am trying to create a Guardfile inside a small Ruby with some Ruby files and RSpec tests. This not a Rails project.

When I run gem install guard I get the following:

$ gem install guard
Fetching: listen-1.3.1.gem (100%)
Successfully installed listen-1.3.1
Fetching: lumberjack-1.0.4.gem (100%)
Successfully installed lumberjack-1.0.4
Fetching: guard-1.8.3.gem (100%)
Successfully installed guard-1.8.3
Installing ri documentation for listen-1.3.1
Installing ri documentation for lumberjack-1.0.4
unable to convert "\xCF" from ASCII-8BIT to UTF-8 for bin/fsevent_watch_guard, skipping
Installing ri documentation for guard-1.8.3
3 gems installed

Obviously "\xCF" should have been installed, but it was not. I cannot figure out what this is, and whether it is the likely cause of my problem.

Later, when I try to create a guard for the RSpec tests, the following occurs:

$ guard init rspec
19:45:11 - INFO - Writing new Guardfile to /home/kathryn/demo3/Guardfile
19:45:11 - ERROR - Could not load 'guard/rspec' or '~/.guard/templates/rspec' or find class Guard::Rspec

As the INFO suggests, a new Guardfile is created, but it is filled with a note directing me to the README for the gem rather than a guard for RSpec. If I manually add the guard for RSpec, and then try to run guard, the result is:

$ guard
19:41:03 - ERROR - Could not load 'guard/rspec' or find class Guard::Rspec
19:41:03 - ERROR - cannot load such file -- guard/rspec
19:41:03 - ERROR - Invalid Guardfile, original error is:
> [#] undefined method `new' for nil:NilClass
19:41:03 - ERROR - No guards found in Guardfile, please add at least one.
19:41:03 - INFO - Guard is using NotifySend to send notifications.
19:41:03 - INFO - Guard is using TerminalTitle to send notifications.
19:41:04 - INFO - Guard is now watching at '/home/kathryn/demo3'

I see that the gem cannot find some files that it needs, but I'm not really sure where to go from here. This is my first time using guard. Any help is appreciated.

This is my current Guardfile:

guard :rspec do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb') { "spec" }
end

That was not generated automatically. When I first created the Guardfile, the contents were:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

I added the guard for RSpec that appeared as the Standard RubyGem project guard here: https://github.com/guard/guard-rspec. (To be clear, I am not using that gem. It was just an easy place to find the guard.)

like image 777
keb Avatar asked Feb 15 '23 06:02

keb


1 Answers

Once the guard-rspec gem is installed, it should "Just Work".

Here are the steps I am doing to get this to load cleanly:

▶ gem install guard-rspec rspec
Fetching: rspec-core-2.14.5.gem (100%)
Successfully installed rspec-core-2.14.5
Fetching: diff-lcs-1.2.4.gem (100%)
Successfully installed diff-lcs-1.2.4
Fetching: rspec-expectations-2.14.2.gem (100%)
Successfully installed rspec-expectations-2.14.2
Fetching: rspec-mocks-2.14.3.gem (100%)
Successfully installed rspec-mocks-2.14.3
Fetching: rspec-2.14.1.gem (100%)
Successfully installed rspec-2.14.1
Fetching: guard-rspec-3.0.3.gem (100%)
Successfully installed guard-rspec-3.0.3
Parsing documentation for rspec-core-2.14.5
Installing ri documentation for rspec-core-2.14.5
Parsing documentation for diff-lcs-1.2.4
Installing ri documentation for diff-lcs-1.2.4
Parsing documentation for rspec-expectations-2.14.2
Installing ri documentation for rspec-expectations-2.14.2
Parsing documentation for rspec-mocks-2.14.3
Installing ri documentation for rspec-mocks-2.14.3
Parsing documentation for rspec-2.14.1
Installing ri documentation for rspec-2.14.1
Parsing documentation for guard-rspec-3.0.3
Installing ri documentation for guard-rspec-3.0.3
Done installing documentation for rspec-core, diff-lcs, rspec-expectations, rspec-mocks, rspec, guard-rspec after 15 seconds
Successfully installed rspec-2.14.1
Parsing documentation for rspec-2.14.1
Done installing documentation for rspec after 0 seconds
7 gems installed

Once that is done, I do this command:

▶ guard init rspec
00:55:13 - INFO - rspec guard added to Guardfile, feel free to edit it

And my Guardfile looks like this:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  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"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

And when I do the guard start command, those errors do not show:

▶ guard start
00:57:08 - INFO - Guard uses NotifySend to send notifications.
00:57:08 - INFO - Guard uses Tmux to send notifications.
00:57:08 - INFO - Guard uses TerminalTitle to send notifications.
00:57:09 - INFO - Guard::RSpec is running
00:57:09 - INFO - Guard is now watching at '/home/vgoff/my_gems'
like image 142
vgoff Avatar answered Feb 17 '23 20:02

vgoff