使用guard和phpunit插件守护

时间:2013-12-09 21:04:30

标签: phpunit laravel-4 guard

当我运行guard init时出现错误

app>guard init
14:56:14 - ERROR - Could not load 'guard/phpunit' or '~/.guard/templates/phpunit
' or find class Guard::Phpunit

保护文件已创建,但为空。它应该包含此代码

guard 'phpunit', :cli => 'colors' do
watch(%r{^.+Test.php$})
end

但是当我手动编辑文件以包含它并运行后卫时我得到了

app>guard
14:59:32 - ERROR - Could not load 'guard/phpunit' or find class Guard::Phpunit
14:59:32 - ERROR - C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb
:1637:in `raise_if_conflicts'
> [#] C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:746:in `acti
vate'
> [#] C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb:212:in `rescue in try_acti
vate'
> [#] C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb:209:in `try_activate'
> [#] C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `resc
ue in require'
> [#] C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `requ
ire'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/plugin_util.rb:1
00:in `plugin_class'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/plugin_util.rb:5
7:in `initialize_plugin'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard.rb:167:in `add_p
lugin'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:175:in `b
lock in guard'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:173:in `e
ach'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:173:in `g
uard'
> [#] C:/Users/Mark/Dropbox/www/trainercompare/app/Guardfile:4:in `_instance_eva
l_guardfile'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile/evalua
tor.rb:121:in `instance_eval'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile/evalua
tor.rb:121:in `_instance_eval_guardfile'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile/evalua
tor.rb:37:in `evaluate_guardfile'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/setuper.rb:144:i
n `evaluate_guardfile'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/setuper.rb:62:in
 `setup'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/commander.rb:24:
in `start'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/cli.rb:96:in `st
art'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb:27:in
`run'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:120
:in `invoke_command'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:in `dispat
ch'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/base.rb:439:in `s
tart'
> [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/bin/guard:6:in `<top (requ
ired)>'
> [#] C:/Ruby193/bin/guard:23:in `load'
> [#] C:/Ruby193/bin/guard:23:in `<main>'
14:59:32 - ERROR - Invalid Guardfile, original error is:
> [#] undefined method `superclass' for nil:NilClass
C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/plugin_util.rb:57:in `
initialize_plugin': undefined method `superclass' for nil:NilClass (NoMethodErro
r)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard.rb:167:in
 `add_plugin'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:17
5:in `block in guard'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:17
3:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/dsl.rb:17
3:in `guard'
        from C:/Users/Mark/Dropbox/www/trainercompare/app/Guardfile:4:in `_insta
nce_eval_guardfile'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile
/evaluator.rb:121:in `instance_eval'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile
/evaluator.rb:121:in `_instance_eval_guardfile'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/guardfile
/evaluator.rb:37:in `evaluate_guardfile'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/setuper.r
b:144:in `evaluate_guardfile'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/setuper.r
b:62:in `setup'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/commander
.rb:24:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/lib/guard/cli.rb:96
:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb
:27:in `run'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation
.rb:120:in `invoke_command'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:in
`dispatch'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/base.rb:43
9:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-2.2.4/bin/guard:6:in `<to
p (required)>'
        from C:/Ruby193/bin/guard:23:in `load'
        from C:/Ruby193/bin/guard:23:in `<main>'

我认为问题在于guard / phpunit是一个废弃的项目,并且尚未更新以支持最新的后卫。我认为这是因为当我删除所有与防护2.2.4相关的宝石文件并且仅留下与防护1.8.3防护相关的文件时将运行并观察文件并运行phpunit一次(失败它不应该)然后拒绝继续看着它不能完全发挥作用,但又向前迈进了一步。

  1. 任何人都可以帮我解决一下吗?
  2. 我不是rubyist但是guard / phpunit中的代码看起来很简单,任何人都可以给我一个链接,解释如何确保插件与guard 2.2.4兼容吗?我可以自己尝试一下
  3. 还有其他想法吗?
  4. 我不是rubyist,但是guard / phpunit中的代码看起来很简单,我很想知道

3 个答案:

答案 0 :(得分:1)

  

我认为问题在于guard / phpunit是一个废弃的项目,并且尚未更新以支持最新的后卫。

没有必要为最新的Guard版本升级Guard插件,因为这些更改是向后兼容的。

通常,您需要安装Bundler来管理您的宝石,并为应用程序设置加载路径以查找相关的宝石。所以如果你有例如您Gemfile

中的以下内容
source 'https://rubygems.org'
ruby '2.0.0'

gem 'guard-phpunit'

然后你可以用

安装Guard和Guard :: PhpUnit
bundle exec guard

另外,您是否看到guard-phpunit2已发布为{{1}}?

答案 1 :(得分:0)

我遇到了这个问题,而且非常痛苦。目前我切换到linux,这就是为什么我无法测试解决方案。但它应该可以正常工作。

  • 完全去除所有红宝石和红宝石。
  • 下载并安装ruby旧版本,例如1.9 rubyInstaller site 1http://rubyinstaller.org/downloads/
  • 也从该网站下载开发工具。 Check this answer before setup, setup like this answer
  • 您需要安装才能显示消息/通知Growl Notifications for windows
  • gem install guard-phpunit(它将自动安装其依赖防护版本)
  • gem install ruby​​_gntp
  • 通过cmd运行'guard'命令构建您的Web应用程序目录,并在Windows背景中使用growl通知软件
  • 运行所有测试按回车键,第一次从guard执行测试时,您将在ResultPrinter.php文件中获得allCompletlyImplemented()错误,在cmd中您将获得文件位置。将所有出现的allCompletlyImplemented()替换为该文件中的allCompletelyImplemented()

- 注意:

希望它有效。手指交叉。

答案 2 :(得分:0)

我有同样的问题。 我使用guard-phpunit2和这个Guardfile

guard 'phpunit2', :cli => '--colors', :tests_path => 'tests', :command => "./vendor/bin/phpunit" do
  watch(%r{^.+Test\.php$})
end

现在工作正常