2016-04-20 10 views
0

Ich habe ein Schienen Projekt mit capybara 2.6.2 und capybara-webkit 1.8.0.Capybara rspec Test dauert sehr lange - warum?

Ich habe einen einfachen Feature-Test, der wie folgt lautet:

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 

Der Test erfolgreich verläuft. Das Problem ist, es dauert diese Zeitspanne zu laufen:

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

Dies scheint lächerlich lang! Während der Ausführung ist meine CPU fast leer und ich bin mir nicht sicher, was die Ausführungszeit verursacht. Ist das eine vernünftige normale Zeit für solch einen einfachen Test? Bitte helfen Sie!

Ich weiß nicht, ob dies helfen wird, aber das ist meine spec_helper.rb Datei:

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

Das ist eine lächerliche Zeit für einen einzigen Test. Aktivieren Sie den Debug-Modus in Capybara-Webkit und sehen Sie, was diese Zeit verbraucht. Nebenbei sollten Sie eql nicht mit current_path verwenden, da dies zu flockigen Tests führen kann - verwenden Sie 'expect (page) .to have_current_path (new_seller_profile_path)' - Eine andere Sache, die Sie ausprobieren sollten, wäre, unbekannte URLs zuzulassen und zu sehen, ob das Drittanbieter-Asset Laden das verlangsamt die Seiten –

Antwort

0

Es wurde für 3rd-Party-Javascripts warten - Debug-Modus eingeschaltet war der Schlüssel zum herauszufinden, was hängen up Capybara Webkit. Danke Tom Walpole.