gpt4 book ai didi

ruby - 新生成的 Guardfile 为空

转载 作者:数据小太阳 更新时间:2023-10-29 07:25:52 24 4
gpt4 key购买 nike

我正在尝试使用一些 Ruby 文件和 RSpec 测试在小型 Rub​​y 中创建一个 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 的 guard。如果我手动为 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 . (需要说明的是,我没有使用那个 gem 。它只是一个很容易找到守卫的地方。)

最佳答案

安装 guard-rspec gem 后,它应该“正常工作”。

以下是我为使它干净地加载而正在执行的步骤:

▶ 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

完成后,我执行此命令:

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

我的 Guardfile 看起来像这样:

# 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

当我执行 guard start 命令时,这些错误不会显示:

▶ 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'

关于ruby - 新生成的 Guardfile 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com