【发布时间】:2013-09-18 03:06:29
【问题描述】:
我正在尝试在一个带有一些 Ruby 文件和 RSpec 测试的小型 Ruby 中创建一个 Guardfile。这不是 Rails 项目。
当我运行 gem install guard 时,我得到以下信息:
$ 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
显然“\xCF”应该已经安装,但它没有。我无法弄清楚这是什么,以及它是否可能是我的问题的原因。
后来,当我尝试为 RSpec 测试创建保护时,会发生以下情况:
$ 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
正如 INFO 建议的那样,创建了一个新的 Guardfile,但它充满了一条说明,指示我查看 gem 的 README,而不是 RSpec 的守卫。如果我手动为RSpec添加保护,然后尝试运行guard,结果是:
$ 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'
我看到 gem 找不到它需要的一些文件,但我不确定从这里去哪里。这是我第一次使用守卫。任何帮助表示赞赏。
这是我当前的 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
这不是自动生成的。当我第一次创建Guardfile时,内容是:
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
我在此处添加了作为标准 RubyGem 项目保护的 RSpec 保护:https://github.com/guard/guard-rspec。 (需要说明的是,我没有使用那个宝石。它只是一个容易找到守卫的地方。)
【问题讨论】:
-
"convert "\xCF" from ASCII-8BIT to UTF-8 "只是报告它无法将该字符从一个字符集转换为另一个字符集。不表示需要安装。您执行了命令
guard init?执行此操作时,您应该最终得到一个 Guardfile,并且您需要根据自己的目的对其进行编辑。看起来会发生这种情况。发布您当前的Guardfile。 -
@vgoff 我已经编辑了我的帖子以包含我当前的 Guardfile 和运行
guard init rspec时生成的 Guardfile。 -
好的,你自己创建这个文件没有问题。
-
即使我手动创建了文件,当我运行
guard时,它仍然会生成我上面显示的一系列四个错误。 -
guard/rspec是问题所在。如果您不使用宝石,它似乎。重命名警卫组,从 rspec 到 ...嗯...不知道你会命名它。也许只是:test。在我为模仿您所描述的作品而制作的骨架中。有类似的错误。如果您打算使用rspec,请继续使用guard-rspecgem。