The newly created Guardfile is empty

I am trying to create a Guardfile inside a small Ruby with some Ruby files and RSpec tests. This is 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" must be installed, but it is not. I can’t understand what it is and whether this is the probable cause of my problem.

Later, when I try to create protection for RSpec tests, the following happens:

 $ 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 INFO prompts, a new Guardfile is created, but it is filled with a note directing me to the README for the gem, and not to the guard for RSpec. If I manually add protection for RSpec and then try to start guard , the result is as follows:

 $ 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 stone cannot find the files that it needs, but I'm not quite sure where to go from here. This is my first time using security. 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 

It was not created automatically. When I first created the Guardfile, the content was:

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

I added a guard for RSpec, which appeared as the main protector of the RubyGem project here: https://github.com/guard/guard-rspec . (To be clear, I do not use this gem. It was a simple place to find a guard.)

+4
source share
1 answer

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

Here are the steps I take to get this to download:

 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 this is done, I will make 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 execute the guard start command, these errors are not displayed:

 ▶ 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' 
+8
source

Source: https://habr.com/ru/post/1502716/


All Articles