如何让我的 Guard/rspec 测试运行得更快
我在 ruby 1.9.2 之上的 Rails 3.1 应用程序中运行以下 gem:
group :test, :development do
gem 'turn', '<0.8.3'
gem 'rspec-rails'
gem 'capybara'
gem 'guard-rspec'
gem 'minitest'
gem 'ruby_gntp'
gem "win32console", "~> 1.3.0"
end
我仅通过运行命令初始化了guard 和 rspec
rails g integration_test MyApp
。
因此,我只有该命令生成的一个示例测试。它看起来像这样:
require 'spec_helper'
describe "Tasks" do
describe "GET /tasks" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get tasks_index_path
response.status.should be(200)
end
end
end
出于某种原因,当我运行守卫时,守卫和 rspec 需要 3.5 到 5 秒之间的时间,只是在小测试中失败了。据我所知,他们的机器在 Mac 上运行这个精确测试大约需要 0.0159 秒。我可以做什么来提高这些测试的性能?
我在 Windows 7 机器上运行它。
有人处理过这种情况吗?
I am running the following gems in a rails 3.1 app ontop of ruby 1.9.2:
group :test, :development do
gem 'turn', '<0.8.3'
gem 'rspec-rails'
gem 'capybara'
gem 'guard-rspec'
gem 'minitest'
gem 'ruby_gntp'
gem "win32console", "~> 1.3.0"
end
I have only initialized guard and rspec by running the
rails g integration_test MyApp
command.
so, I have only the one sample test that is generated by the command. it looks like this:
require 'spec_helper'
describe "Tasks" do
describe "GET /tasks" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get tasks_index_path
response.status.should be(200)
end
end
end
for some reason, when i run guard, it takes guard and rspec between 3.5 and 5 seconds just fail this on little test. On the tuts I've seen, their machine runs this exact test in about .0159 seconds on a Mac. What can I do to increase the performance of these test?
I am running this on a Windows 7 machine.
Has anyone dealt with this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@jstim 上面所建议的,这个问题的一个词答案是 Spork。
至少,您需要将以下内容添加到您的
:test, :development
块中:这里是 Spork 自述文件。
它的作用是设置一个预加载块,您可以根据需要放入任意数量的应用程序。当然,这样做的好处是测试速度更快,因为不需要每次都运行这些东西。缺点是,如果您对预加载的内容进行更改,它将不会经过测试。进行此类更改后,您需要重新启动 Spork。
The one word answer to this question, as @jstim suggested above, is Spork.
At minimum, you'll want to add the following to your
:test, :development
block:Here is a link to the Spork README.
What it does is sets up a preload block that you can put as much or as little of your app in as you like. The benefit, of course, is faster tests because of all that stuff that doesn't need to be run each time. The drawback is if you make changes to the stuff that's preloaded, it will not be tested. You need to restart Spork after such changes.