Class: RuboCop::Cop::OpenProject::NoSleepInFeatureSpecs

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb

Overview

Checks that feature specs do not use ‘sleep` greater than 1 second.

Relying on ‘sleep` for synchronization reduces overall performance of the test suite. Consider using Capybara `have_*` matchers or rspec-wait `wait_for` method instead.

Examples:


# bad
sleep 20

# bad
sleep 1.5

# bad
delay = 15
sleep delay

# good (use sparingly)
sleep 1

# good
expect(page).not_to have_text("please wait")

# good
expect(page).to have_text("success")

good
wait_for { work_package.reload.subject }.to eq("Updated name")

Constant Summary collapse

MSG =
"Avoid using `sleep` greater than 1 second in feature specs. " \
"It will reduce overall performance of the test suite. " \
"Consider using Capybara `have_*` matchers or rspec-wait " \
"`wait_for` method instead."

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb', line 43

def on_send(node)
  return unless feature_spec?(processed_source)

  on_sleep_call(node) do |args|
    add_offense(node, message: MSG) if sleeping_too_much?(args[0])
  end
end