阻止工厂女孩日志记录

发布于 2024-08-11 21:39:30 字数 3348 浏览 3 评论 0原文

澄清一下,我并不是某个残忍的工厂老板,试图让女工们闭嘴。我遇到一个非常烦人的问题,当在我的规范中使用 Thoughtbot 的工厂女孩​​时,每次使用 Factory.create(:foo) 时,新创建的 ActiveRecord 模型实例都会记录到控制台。这使得查看控制台输出更加难以直观地过滤掉所有额外的日志记录。是否有某处的设置或可以设置的标志可以消除此额外的日志记录?

下面是我的 rspec 输出的一个小示例。这 '。'在本例中,每行的开头都是成功的测试。

loading autotest/rspec
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/bin/spec --autospec spec/publisher_spec.rb -O spec/spec.opts 
#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: "2009-11-18 19:11:56", updated_at: "2009-11-18 19:11:56", draft: true, draft_origin_id: 3, draft_deleted: false>
#<Event id: nil, oid: "bumbershoo", name: "Bumbershoot", short_name: "bumbershoot", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Notification id: nil, oid: "8P93CNEcl0", event_id: 3, name: "Penut Butter Jelly Time", url: nil, type: "Alert", priority: 10, last_displayed: "2009-11-16 19:11:54", format: nil, content: "IT'S PENUT BUTTER JELLY TIME.  WHERE YOU AT? WHERE ...", image: nil, is_active: true, created_at: nil, updated_at: nil, updated_by: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Notification id: nil, oid: "8P93CNEcl0", event_id: 3, name: "Penut Butter Jelly Time", url: nil, type: "Alert", priority: 10, last_displayed: "2009-11-16 19:11:54", format: nil, content: "IT'S PENUT BUTTER JELLY TIME.  WHERE YOU AT? WHERE ...", image: nil, is_active: true, created_at: "2009-11-18 19:11:57", updated_at: "2009-11-18 19:11:57", updated_by: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, draft: true, draft_origin_id: 3, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Event id: nil, oid: "bumbershoo", name: "Bumbershoot", short_name: "bumbershoot", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>

我已经多次检查我的规格,看看我是否在任何地方有“puts foo.inspect”,但我没有。我使用自动测试和通常单独运行测试的所有 rspec 和黄瓜测试都会发生这种情况。

这是我与上述输出相关的 factories.rb 文件。注意:我的工厂里发生了一些小事。rb。

[更新:2009-11-20] 只是想保持新鲜感,看看其他人是否有任何想法。

Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot's factory girl in my specs, every time Factory.create(:foo) is used, the newly created ActiveRecord model instance is logged to the console. This makes looking at my console output more difficult to visually filter out all of the extra logging. Is there a setting somewhere or a flag that can be set that will silence this extra logging?

Below is a small example of my rspec output. The '.' at the beginning of each line, in this case, is a successful test.

loading autotest/rspec
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/bin/spec --autospec spec/publisher_spec.rb -O spec/spec.opts 
#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: "2009-11-18 19:11:56", updated_at: "2009-11-18 19:11:56", draft: true, draft_origin_id: 3, draft_deleted: false>
#<Event id: nil, oid: "bumbershoo", name: "Bumbershoot", short_name: "bumbershoot", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Notification id: nil, oid: "8P93CNEcl0", event_id: 3, name: "Penut Butter Jelly Time", url: nil, type: "Alert", priority: 10, last_displayed: "2009-11-16 19:11:54", format: nil, content: "IT'S PENUT BUTTER JELLY TIME.  WHERE YOU AT? WHERE ...", image: nil, is_active: true, created_at: nil, updated_at: nil, updated_by: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Notification id: nil, oid: "8P93CNEcl0", event_id: 3, name: "Penut Butter Jelly Time", url: nil, type: "Alert", priority: 10, last_displayed: "2009-11-16 19:11:54", format: nil, content: "IT'S PENUT BUTTER JELLY TIME.  WHERE YOU AT? WHERE ...", image: nil, is_active: true, created_at: "2009-11-18 19:11:57", updated_at: "2009-11-18 19:11:57", updated_by: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, draft: true, draft_origin_id: 3, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
#<Event id: nil, oid: "bumbershoo", name: "Bumbershoot", short_name: "bumbershoot", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>
.#<Event id: nil, oid: "mainEvent1", name: "Main Event", short_name: "mainevent", time_zone: "PST", created_at: nil, updated_at: nil, draft: true, draft_origin_id: nil, draft_deleted: false>

I have picked over my specs many times to see if I have a "puts foo.inspect" anywhere, and I do not. This happens for all of my rspec and cucumber tests using autotest and normally running tests individually.

Here is my factories.rb file that relates to the above output. Note: there is some minor fanciness happening in my factories.rb.

[Update:2009-11-20] Just trying to keep this fresh, and see if someone else may have any ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-08-18 21:39:30

您能否提供更多有关您在哪里看到测井线的更多详细信息?您是否正在运行rake spec?您可以复制/粘贴一些示例输出吗?

Can you give some more details on where exactly you're seeing the logging lines? Are you running rake spec? Can you copy/paste some example output?

追星践月 2024-08-18 21:39:30

我不知道如何或为什么,但这个问题已经自行解决了。我只能推测这是 Factory Girl 或 rspec 的更新。也许我删除了代码中的一些日志记录。我不能确定。

I don't know how or why, but this problem has resolved its self. I can only speculate that it was an update to Factory Girl or rspec. Maybe I removed some logging in my code. I can't be sure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文