2016-04-20 7 views
0

私はrspec 3.4.0capybara 2.6.2capybara-webkit 1.8.0を使っている。Capybara rspecテストには時間がかかります - なぜですか?

私は次のように単純な機能テストがあります。

require 'rails_helper' 

RSpec.feature "Seller Features", type: :feature do 

    let!(:sub_category) { FactoryGirl.create(:sub_category) } 

#all tests will create a user - sign them in and land them on the homepage 
    background do 
    sign_in_as 
    end 

scenario "Buyer creates a seller profile", :js => true do 

    click_link("SELL ON SITE",match: :first) 
    expect(page).to have_text("Reach thousands of customers in your area") 
    click_link("Create an Activity",match: :first) 
    expect(current_path).to eql (new_seller_profile_path) 

    fill_in "seller_profile[business_name]", :with => "Test company" 
    fill_in "seller_profile[business_email]", :with => "[email protected]" 
    fill_in "seller_profile[business_phone_number]", :with => "07771330510" 
    fill_in "seller_profile[business_description]", :with => "This is a test company" 

    find('label[for="social"]').click 


    find("#facebook-placeholder").click 

    fill_in "seller_profile[business_facebook_url]", :with => "https://www.facebook.com/test" 

    click_button("CREATE AN ACTIVITY") 

    fill_in "seller_profile[requested_postcode]", :with => "EH21 8PB" 

    click_button("Submit") 

    click_link("Continue") 

    expect(page).to have_text("Choose the type of activity that you want to create") 

end 

end 

をテストが正常に渡されます。問題は、実行するのにこの時間がかかることです。

Finished in 4 minutes 26.2 seconds (files took 7.19 seconds to load) 

これはちょっと長いようですね!実行中にCPUがほとんどアイドル状態になっているため、実行時間の長さの原因は不明です。このようなシンプルな機能テストには、これは普通の時間ですか?助けてください!

これが役立つ場合、私は知らないが、これは私のspec_helper.rbファイルです。それは、サードパーティのJavaScriptのを待っていた

ENV["RAILS_ENV"] ||= "test" 
ENV['SERVER_NAME'] = "user.myapp.com" 

require File.expand_path("../../config/environment", __FILE__) 
require "rspec/rails" 


Capybara::Webkit.configure do |config| 
    # Enable debug mode. Prints a log of everything the driver is doing. 
    config.debug = false 

    config.allow_unknown_urls 
    # Allow pages to make requests to any URL without issuing a warning. 

    # Allow a specifc domain without issuing a warning. 
    config.allow_url("https://checkout.stripe.com") 
config.allow_url("https://checkout.stripe.com/v3/data/languages/en.json") 


    # Timeout if requests take longer than 5 seconds 
    config.timeout = 60 

    # Don't raise errors when SSL certificates can't be validated 
    config.ignore_ssl_errors 

end 

Capybara.javascript_driver = :webkit 

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

RSpec.configure do |config| 
    # rspec-expectations config goes here. You can use an alternate 
    # assertion/expectation library such as wrong or the stdlib/minitest 
    # assertions if you prefer. 
    config.use_transactional_fixtures = false 
    config.before(:suite) do 
    DatabaseCleaner.clean_with(:truncation) 
    end 

    config.before(:each) do |example| 
    DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction 
    DatabaseCleaner.start 
    end 

    config.after(:each) do 
    DatabaseCleaner.clean 
    end 

    config.include SignInHelpers, type: :feature 
    config.mock_with :rspec 

    config.expect_with :rspec do |expectations| 
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true 
    end 

    # rspec-mocks config goes here. You can use an alternate test double 
    # library (such as bogus or mocha) by changing the `mock_with` option here. 
    config.mock_with :rspec do |mocks| 
    # Prevents you from mocking or stubbing a method that does not exist on 
    # a real object. This is generally recommended, and will default to 
    # `true` in RSpec 4. 
    mocks.verify_partial_doubles = true 
    end 
end 
+1

これは、1回のテストではばかげている時間です。 capybara-webkitのデバッグモードをオンにし、その時間を使い果たしているかどうかを確認します。 'expect(page).to have_current_path(new_seller_profile_path)'を使用してください。未知のURLを許可しないようにして、サードパーティの資産ページの読み込みが遅くなる –

答えて

0

- デバッグモードをぶら下げたものを見つけるための鍵となったオンup capybaraウェブキット。ありがとうTom Walpole。

関連する問題