Commit f5e335dd authored by Doug Stull's avatar Doug Stull Committed by Michael Kozono

Resolve Style/NumericPredicate cop exceptions in specs

- no exceptions...
parent 2a5ebef6
...@@ -1025,7 +1025,6 @@ Style/NumericLiteralPrefix: ...@@ -1025,7 +1025,6 @@ Style/NumericLiteralPrefix:
Style/NumericPredicate: Style/NumericPredicate:
EnforcedStyle: comparison EnforcedStyle: comparison
Exclude: Exclude:
- 'spec/**/*'
- 'app/controllers/concerns/issuable_collections.rb' - 'app/controllers/concerns/issuable_collections.rb'
- 'app/controllers/concerns/paginated_collection.rb' - 'app/controllers/concerns/paginated_collection.rb'
- 'app/helpers/graph_helper.rb' - 'app/helpers/graph_helper.rb'
...@@ -1126,8 +1125,6 @@ Style/NumericPredicate: ...@@ -1126,8 +1125,6 @@ Style/NumericPredicate:
- 'lib/tasks/gitlab/gitaly.rake' - 'lib/tasks/gitlab/gitaly.rake'
- 'lib/tasks/gitlab/snippets.rake' - 'lib/tasks/gitlab/snippets.rake'
- 'lib/tasks/gitlab/workhorse.rake' - 'lib/tasks/gitlab/workhorse.rake'
- 'qa/qa/git/repository.rb'
- 'qa/qa/support/wait_for_requests.rb'
- 'ee/app/models/ee/project.rb' - 'ee/app/models/ee/project.rb'
- 'lib/gitlab/usage_data/topology.rb' - 'lib/gitlab/usage_data/topology.rb'
......
...@@ -204,7 +204,7 @@ module QA ...@@ -204,7 +204,7 @@ module QA
alias_method :to_s, :response alias_method :to_s, :response
def success? def success?
exitstatus.zero? exitstatus == 0
end end
end end
......
...@@ -14,13 +14,13 @@ module QA ...@@ -14,13 +14,13 @@ module QA
end end
def finished_all_axios_requests? def finished_all_axios_requests?
Capybara.page.evaluate_script('window.pendingRequests || 0').zero? Capybara.page.evaluate_script('window.pendingRequests || 0').zero? # rubocop:disable Style/NumericPredicate
end end
def finished_all_ajax_requests? def finished_all_ajax_requests?
return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"') return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"')
Capybara.page.evaluate_script('jQuery.active').zero? Capybara.page.evaluate_script('jQuery.active').zero? # rubocop:disable Style/NumericPredicate
end end
def finished_loading?(wait: DEFAULT_MAX_WAIT_TIME) def finished_loading?(wait: DEFAULT_MAX_WAIT_TIME)
......
...@@ -17,7 +17,7 @@ RSpec.describe 'mail_room.yml' do ...@@ -17,7 +17,7 @@ RSpec.describe 'mail_room.yml' do
cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result" cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result"
output, status = Gitlab::Popen.popen(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars) output, status = Gitlab::Popen.popen(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars)
raise "Error interpreting #{mailroom_config_path}: #{output}" unless status.zero? raise "Error interpreting #{mailroom_config_path}: #{output}" unless status == 0
YAML.load(output) YAML.load(output)
end end
......
...@@ -60,7 +60,7 @@ RSpec.describe Groups::Settings::RepositoryController do ...@@ -60,7 +60,7 @@ RSpec.describe Groups::Settings::RepositoryController do
'token' => be_a(String), 'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv| 'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv key, value = kv
key.to_s.start_with?('read_') && !value.to_i.zero? ? scopes << key.to_s : scopes key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes
end end
} }
end end
......
...@@ -77,7 +77,7 @@ RSpec.describe Projects::Settings::RepositoryController do ...@@ -77,7 +77,7 @@ RSpec.describe Projects::Settings::RepositoryController do
'token' => be_a(String), 'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv| 'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv key, value = kv
key.to_s.start_with?('read_') && !value.to_i.zero? ? scopes << key.to_s : scopes key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes
end end
} }
end end
......
...@@ -23,7 +23,7 @@ FactoryBot.define do ...@@ -23,7 +23,7 @@ FactoryBot.define do
end end
create_versions = ->(design, evaluator, commit_version) do create_versions = ->(design, evaluator, commit_version) do
unless evaluator.versions_count.zero? unless evaluator.versions_count == 0
project = design.project project = design.project
issue = design.issue issue = design.issue
repository = project.design_repository repository = project.design_repository
......
...@@ -40,7 +40,7 @@ FactoryBot.define do ...@@ -40,7 +40,7 @@ FactoryBot.define do
) )
version.designs += specific_designs version.designs += specific_designs
unless evaluator.designs_count.zero? || version.designs.present? unless evaluator.designs_count == 0 || version.designs.present?
version.designs << create(:design, issue: version.issue) version.designs << create(:design, issue: version.issue)
end end
end end
......
...@@ -36,7 +36,7 @@ RSpec.describe 'Contributions Calendar', :js do ...@@ -36,7 +36,7 @@ RSpec.describe 'Contributions Calendar', :js do
def get_cell_date_selector(contributions, date) def get_cell_date_selector(contributions, date)
contribution_text = contribution_text =
if contributions.zero? if contributions == 0
'No contributions' 'No contributions'
else else
"#{contributions} #{'contribution'.pluralize(contributions)}" "#{contributions} #{'contribution'.pluralize(contributions)}"
......
...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do ...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
return enum_for(:each) unless block_given? return enum_for(:each) unless block_given?
loop do loop do
break if @count.zero? break if @count == 0
# It is critical to decrement before yielding. We may never reach the lines after 'yield'. # It is critical to decrement before yielding. We may never reach the lines after 'yield'.
@count -= 1 @count -= 1
......
...@@ -169,7 +169,7 @@ RSpec.describe Gitlab::GithubImport::Client do ...@@ -169,7 +169,7 @@ RSpec.describe Gitlab::GithubImport::Client do
expect(client).to receive(:raise_or_wait_for_rate_limit) expect(client).to receive(:raise_or_wait_for_rate_limit)
client.with_rate_limit do client.with_rate_limit do
if retries.zero? if retries == 0
retries += 1 retries += 1
raise(Octokit::TooManyRequests) raise(Octokit::TooManyRequests)
end end
......
...@@ -118,7 +118,7 @@ RSpec.describe Gitlab::Popen::Runner do ...@@ -118,7 +118,7 @@ RSpec.describe Gitlab::Popen::Runner do
stdout: 'stdout', stdout: 'stdout',
stderr: '', stderr: '',
exitstatus: 0, exitstatus: 0,
status: double(exitstatus: exitstatus, success?: exitstatus.zero?), status: double(exitstatus: exitstatus, success?: exitstatus == 0),
duration: 0.1) duration: 0.1)
result = result =
......
...@@ -191,7 +191,7 @@ RSpec.describe Gitlab::TreeSummary do ...@@ -191,7 +191,7 @@ RSpec.describe Gitlab::TreeSummary do
with_them do with_them do
before do before do
create_file('dummy', path: 'other') if num_entries.zero? create_file('dummy', path: 'other') if num_entries == 0
1.upto(num_entries) { |n| create_file(n, path: path) } 1.upto(num_entries) { |n| create_file(n, path: path) }
end end
...@@ -218,7 +218,7 @@ RSpec.describe Gitlab::TreeSummary do ...@@ -218,7 +218,7 @@ RSpec.describe Gitlab::TreeSummary do
with_them do with_them do
before do before do
create_file('dummy', path: 'other') if num_entries.zero? create_file('dummy', path: 'other') if num_entries == 0
1.upto(num_entries) { |n| create_file(n, path: path) } 1.upto(num_entries) { |n| create_file(n, path: path) }
end end
......
...@@ -44,7 +44,7 @@ class BareRepoOperations ...@@ -44,7 +44,7 @@ class BareRepoOperations
yield stdin if block_given? yield stdin if block_given?
end end
unless status.zero? unless status == 0
if allow_failure if allow_failure
return [] return []
else else
......
...@@ -21,7 +21,7 @@ module MemoryUsageHelper ...@@ -21,7 +21,7 @@ module MemoryUsageHelper
def get_memory_usage def get_memory_usage
output, status = Gitlab::Popen.popen(%w(free -m)) output, status = Gitlab::Popen.popen(%w(free -m))
abort "`free -m` return code is #{status}: #{output}" unless status.zero? abort "`free -m` return code is #{status}: #{output}" unless status == 0
result = output.split("\n")[1].split(" ")[1..-1] result = output.split("\n")[1].split(" ")[1..-1]
attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze
......
...@@ -42,7 +42,7 @@ module WaitForRequests ...@@ -42,7 +42,7 @@ module WaitForRequests
private private
def finished_all_rack_requests? def finished_all_rack_requests?
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? Gitlab::Testing::RequestBlockerMiddleware.num_active_requests == 0
end end
def finished_all_js_requests? def finished_all_js_requests?
...@@ -53,12 +53,12 @@ module WaitForRequests ...@@ -53,12 +53,12 @@ module WaitForRequests
end end
def finished_all_axios_requests? def finished_all_axios_requests?
Capybara.page.evaluate_script('window.pendingRequests || 0').zero? Capybara.page.evaluate_script('window.pendingRequests || 0').zero? # rubocop:disable Style/NumericPredicate
end end
def finished_all_ajax_requests? def finished_all_ajax_requests?
return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"') return true if Capybara.page.evaluate_script('typeof jQuery === "undefined"')
Capybara.page.evaluate_script('jQuery.active').zero? Capybara.page.evaluate_script('jQuery.active').zero? # rubocop:disable Style/NumericPredicate
end end
end end
...@@ -44,7 +44,7 @@ module ExceedQueryLimitHelpers ...@@ -44,7 +44,7 @@ module ExceedQueryLimitHelpers
def log_message def log_message
if expected.is_a?(ActiveRecord::QueryRecorder) if expected.is_a?(ActiveRecord::QueryRecorder)
counts = count_queries(strip_marginalia_annotations(expected.log)) counts = count_queries(strip_marginalia_annotations(expected.log))
extra_queries = strip_marginalia_annotations(@recorder.log).reject { |query| counts[query] -= 1 unless counts[query].zero? } extra_queries = strip_marginalia_annotations(@recorder.log).reject { |query| counts[query] -= 1 unless counts[query] == 0 }
extra_queries_display = count_queries(extra_queries).map { |query, count| "[#{count}] #{query}" } extra_queries_display = count_queries(extra_queries).map { |query, count| "[#{count}] #{query}" }
(['Extra queries:'] + extra_queries_display).join("\n\n") (['Extra queries:'] + extra_queries_display).join("\n\n")
...@@ -188,7 +188,7 @@ RSpec::Matchers.define :issue_same_number_of_queries_as do ...@@ -188,7 +188,7 @@ RSpec::Matchers.define :issue_same_number_of_queries_as do
def expected_count_message def expected_count_message
or_fewer_msg = "or fewer" if @or_fewer or_fewer_msg = "or fewer" if @or_fewer
threshold_msg = "(+/- #{threshold})" unless threshold.zero? threshold_msg = "(+/- #{threshold})" unless threshold == 0
["#{expected_count}", or_fewer_msg, threshold_msg].compact.join(' ') ["#{expected_count}", or_fewer_msg, threshold_msg].compact.join(' ')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment