【发布时间】:2011-06-03 04:07:32
【问题描述】:
以下是在一个相当简单的 rails 3 应用程序上使用 time rspec spec 与 time bundle exec spec 的 3 次随机运行。不使用 bundler 总是更快,而且它使用更少的资源,6% vs 17% cpu。
我确信它与处理依赖项的捆绑程序有关,但我想更好地理解这个问题。我尝试练习 TDD,所以我当然会在一天中多次运行测试。如果使用bundle exec 会在速度和资源方面“花费”我,那么我很想找到一种方法来避免使用bundle exec。
我正在使用 rails 3.0.3、ruby 1.9.2、rspec 2.3、bundler 1.0.10
rspec spec 0.47s user 0.13s system 6% cpu 8.758 total
rspec spec 0.47s user 0.12s system 6% cpu 8.521 total
rspec spec 0.46s user 0.12s system 6% cpu 8.528 total
bundle exec rspec spec 1.35s user 0.30s system 17% cpu 9.293 total
bundle exec rspec spec 1.39s user 0.31s system 17% cpu 9.749 total
bundle exec rspec spec 1.37s user 0.30s system 17% cpu 9.490 total
【问题讨论】:
-
bundle exec的行为就像一个沙箱,我想说,它是一个沙箱。想想你通过 git 获得的 gem(因为到目前为止还没有发布特殊补丁 - 这是在 bundle 上下文之外无法访问的 gem)!所以 bundler 会加载/准备你隔离的 gem 环境。如果您通过 git 使用 gems,您确实需要使用 bundle exec,否则会引发错误。 - 如果您只有 rubygems 托管的 gem,您可以离开“bundle exec”,因为您的所有 gem 也可以在全局范围内找到。 -
有点 OT,但如果您担心测试运行时间并且经常运行测试,那么您可能想尝试一下 Spork。它基本上会预加载 Rspec 然后挂钩的测试环境,因此它不必在每次测试之前启动它。 github.com/timcharper/spork
-
我这里有完全相反的问题。有谁知道为什么? stackoverflow.com/questions/7982589/rspec-and-bundle-exec
标签: ruby-on-rails ruby rspec bundler