RenegadeAndy
RenegadeAndy

Reputation: 5690

Capybara rspec test takes a long time to execute - why?

I have a rails project using rspec 3.4.0 capybara 2.6.2 and capybara-webkit 1.8.0.

I have a simple feature test which is as follows:

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

The test passes successfully. The problem is it takes this length of time to run:

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

This seems ridiculously long! During the execution my cpu is almost idle so I am not sure what is causing the length of execution time? Is this a reasonable normal amount of time for such a simple feature test?! Please help!

I don't know if this will help but this is my spec_helper.rb file:

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

Upvotes: 0

Views: 807

Answers (1)

RenegadeAndy
RenegadeAndy

Reputation: 5690

It was waiting for 3rd party javascripts - debug mode turned on was the key to finding out what was hanging up capybara webkit. Thanks Tom Walpole.

Upvotes: 1

Related Questions