水豚:js =>真的很慢

时间:2012-09-25 18:27:50

标签: ruby-on-rails ruby ruby-on-rails-3 rspec capybara

当我切换时:js =>对我的例子来说,确实需要很长时间才能完成第一次测试,然后才能成为可接受的性能

这个样本在0.36722秒内运行,没有:js,58.15秒运行:js =>真

require 'spec_helper'

include UserAbilitiesHelper

describe "Customer Task Pages" do

  subject { page }

  describe "side panel with the history of the tasks related to customer" do
    before do
      visit root_path()
    end

    it { sould have_content(I18n.t("customers.tasks.side.title")) }


  end

  describe "side panel with the history of the tasks related to customer" do
    before do
      visit root_path()
    end

    it { sould have_content(I18n.t("customers.tasks.side.title")) }


  end


end

我的Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.5'
gem 'pg', '0.12.2'

gem "meta_search"

# Bootstrap and layouting
gem 'bootstrap-sass', '2.0.3'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'rails3-jquery-autocomplete'

#test support
gem 'faker', '1.0.1'

#login rules
gem 'devise'
gem 'cancan'

#criptar
gem 'bcrypt-ruby', '3.0.1'

#BR
gem 'brazilian-rails'
gem 'rails-i18n'

group :development do
    gem 'annotate', '~> 2.4.1.beta'
    gem 'nested_scaffold'
end

group :development, :test do
  gem 'rspec-rails', '2.10.0'
  gem 'guard-rspec', '0.5.5'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'ruby-debug19'
  gem 'linecache19'
  gem 'factory_girl_rails', '1.4.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
  gem "launchy"
  gem 'ZenTest'
  #MAC OS Especific
  gem 'rb-fsevent', '0.4.3.1', :require => false
  gem 'growl', '1.0.3'

  #Cucumber
  gem 'cucumber-rails', '1.2.1', require: false
  gem 'database_cleaner', '0.7.0'
end

group :production do
  #gem 'pg', '0.12.2'
end

使用

运行
bundle exec rspec

任何一个例子

Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$ bundle exec rspec spec/requests/authentication_pages_spec.rb 
No DRb server is running. Running in local process instead ...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
.....................

Finished in 6.07 seconds
21 examples, 0 failures
Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$ bundle exec rspec spec/requests/authentication_pages_spec.rb 
No DRb server is running. Running in local process instead ...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
............F........

Failures:

  1) Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
     Failure/Error: page.should have_selector('title', text: 'Edit user')
       expected css "title" with text "Edit user" to return something
     # ./spec/requests/authentication_pages_spec.rb:65:in `block (6 levels) in <top (required)>'

Finished in 1 minute 14.18 seconds
21 examples, 1 failure

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:64 # Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Bruno-Guerras-MacBook-Pro:railstutorial brunoguerra$

感谢

2 个答案:

答案 0 :(得分:4)

我发现,我的DNS服务器太慢,我改变了我的DNS服务器并且问题解决了,我做的另一件事是提高测试速度是配置这些参数webrick configure webrik speedup但是,它解决了同样的问题,DNS服务器! urgh !!!

答案 1 :(得分:2)

您也可以尝试更改驱动程序:webkit_debug,然后重新运行您的规范,以查看是否有任何脚本不需要在页面上加载。

Capybara.javascript_driver = :webkit_debug

然后将任何网址添加到黑名单

config.before(:each, js: true) do
   page.driver.browser.url_blacklist = ["http://use.typekit.net"]
end