RSpec 并使 put 或 logger.info 正常工作
当我运行“rspec”之类的规范时。从命令行,如果我在规范中调用该代码,我可以在控制台中看到 put 或 logger.info 。但是,如果对 logger.info 或 put 的调用位于我正在测试的控制器中,则它不会输出到 test.log 文件或控制台窗口。
我正在使用 RSpec 2 和 Rails 3.0.4
另外,这是一个 RefineryCMS 站点,但我们在我们正在尝试测试的 Refinery CMS 外部有几个控制器。当我在普通站点中执行 put 或 logger.info 时,即使运行 RSpec,它似乎也能正常工作。
谢谢。
When I'm running my specs like "rspec ." from the command line, I can see puts or logger.info in the console, if i call that code in my spec. However, if the call to logger.info or puts is in my controller which I'm testing, it doesn't output to the test.log file or the console window.
I'm using RSpec 2 and Rails 3.0.4
Also, this is a refinerycms site, but we have a couple of controllers external to the Refinery CMS we are trying to test. When I do a puts or logger.info in a normal site, it seems to work fine, even running RSpec.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我们终于弄清楚了。
问题是 Refinery 需要创建默认用户,否则它不允许您访问前端页面。当您第一次启动它时,它会提示用户创建默认的管理员登录名。因此,当我们运行测试时,我们的代码从未受到攻击。 Refinery 在测试期间将“浏览器”重定向到“创建第一个用户”页面。
我们使用默认用户创建了一个种子,然后一切又恢复正常了。所以问题从来都不是“puts”或“logger.info”在精炼厂或 rspec 中不起作用。问题是在测试过程中,我们从未接触到控制器。
Okay so we finally figured this out.
The issue is that Refinery requires a default user to be created or it does not let you hit front end pages. When you first fire it up, it prompts the user to create a default admin login. So when we were running our tests, our code was never getting hit. Refinery was redirecting the "browser" during test time to the "create a first user" page.
We created a seed with a default user and then everything worked again. So the issue was never that doing a "puts" or "logger.info" didn't work in refinery or rspec. It was that during testing, we never were getting to our controller.