如何解决“rake test”问题?我的 rake 任务列表中缺失了?
我有两个应用程序。其中一个是我使用rails new...构建的一个非常简单的应用程序,添加了单元测试并运行了单元测试。另一个是运行良好的现有应用程序,但我想为其添加一些测试。在 AppA(简单的)中,当我运行 rake -vT 时,我看到:
...
rake test # Runs test:units, test:functionals, test:integrati...
rake test:recent # Run tests for {:recent=>"test:prepare"} / Test re...
rake test:single # Run tests for {:single=>"test:prepare"}
rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Te...
...
这看起来很正常。但是,当我在 AppB(现有应用程序)中运行相同的命令时,我没有看到任何与 rake test 相关的命令。我的第一个想法是将测试从 AppA“转移”到 AppB,看看是否有帮助。因此,我擦除了 AppB 中测试目录中的所有内容,并从 AppA 中复制了测试目录。应用列表中仍然没有rake test
。但我可以通过 ruby -Itest test/unit/first_test.rb 在 AppB 中运行单元测试(奇怪的是我必须注释掉fixtures :all 才能让它工作,也许这是一个线索)。
I have two apps. One is a very simple app that I built with rails new...
, added a unit test to and ran the unit test. The other is an existing app that is running fine but I'd like to add some tests to it. In AppA (the simple one) when I run rake -vT
I see:
...
rake test # Runs test:units, test:functionals, test:integrati...
rake test:recent # Run tests for {:recent=>"test:prepare"} / Test re...
rake test:single # Run tests for {:single=>"test:prepare"}
rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Te...
...
Which seems normal. But when I run that same command in AppB (the existing app) I don't see any of the commands related to rake test
. My first thought was to just 'bring over' the tests from AppA to AppB to see if that would help. So I wiped all content from the test directory in AppB and copied over the test directory from AppA. Still no rake test
in the list of apps. But I can run a unit test in AppB via ruby -Itest test/unit/first_test.rb
(oddly I have to comment out fixtures :all
to get it to work, maybe that's a clue).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
昨晚找到了这个问题的答案。新应用程序的 application.rb 有:
我有:
我这样做是因为我认为我正在遵循有关 MongoMapper 的指南。前进几个版本,最后一行被注释掉了——这就是真正的原因。我在将 ODM 切换到 Mongoid 的同时将其注释掉。我不知道为什么我把它注释掉了,但这确实做到了。
Found the answer to this last night. Where a new app's application.rb has:
I had:
I did that because I was following a guide about MongoMapper I think. Go forward a few versions and the last line is commented out -- that's the real reason. I commented it out at the same time I switched my ODM over to Mongoid. I'm not sure why I commented it out, but that definitely did it.
如果不知道
Rakefile
的内容,就很难对其进行调试,但您可能会错过Rakefile
中的.load_tasks
调用。如果您使用的是 Rails 3,您应该有类似这样的内容:
该行将负责加载默认的 Rails 任务。您也许能够在
Rakefile
中完成相同的调用require "rails/tasks"
。Without knowing the contents of your
Rakefile
it's really hard to debug this, but you might be missing the.load_tasks
call in theRakefile
.If you're using Rails 3 you should have something like this:
That line will take care of loading the default Rails tasks. You might be able to accomplish the same calling
require "rails/tasks"
in yourRakefile
.