summaryrefslogtreecommitdiff
path: root/spec/tooling
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tooling')
-rw-r--r--spec/tooling/danger/product_intelligence_spec.rb14
-rw-r--r--spec/tooling/danger/project_helper_spec.rb110
-rw-r--r--spec/tooling/danger/specs_spec.rb2
-rw-r--r--spec/tooling/graphql/docs/renderer_spec.rb4
-rw-r--r--spec/tooling/quality/test_level_spec.rb4
-rw-r--r--spec/tooling/rspec_flaky/flaky_example_spec.rb76
-rw-r--r--spec/tooling/rspec_flaky/flaky_examples_collection_spec.rb28
-rw-r--r--spec/tooling/rspec_flaky/listener_spec.rb7
-rw-r--r--spec/tooling/rspec_flaky/report_spec.rb4
9 files changed, 88 insertions, 161 deletions
diff --git a/spec/tooling/danger/product_intelligence_spec.rb b/spec/tooling/danger/product_intelligence_spec.rb
index c090dbb4de4..d0d4b8d4df4 100644
--- a/spec/tooling/danger/product_intelligence_spec.rb
+++ b/spec/tooling/danger/product_intelligence_spec.rb
@@ -65,13 +65,25 @@ RSpec.describe Tooling::Danger::ProductIntelligence do
it { is_expected.to be_empty }
end
end
+ end
+
+ describe '#skip_review' do
+ subject { product_intelligence.skip_review? }
context 'with growth experiment label' do
before do
allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(true)
end
- it { is_expected.to be_empty }
+ it { is_expected.to be true }
+ end
+
+ context 'without growth experiment label' do
+ before do
+ allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(false)
+ end
+
+ it { is_expected.to be false }
end
end
end
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb
index ec475df6d83..f13083bdf0a 100644
--- a/spec/tooling/danger/project_helper_spec.rb
+++ b/spec/tooling/danger/project_helper_spec.rb
@@ -3,7 +3,7 @@
require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'danger'
-require 'danger/plugins/helper'
+require 'danger/plugins/internal/helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../danger/plugins/project_helper'
@@ -20,22 +20,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
before do
allow(project_helper).to receive(:helper).and_return(fake_helper)
- end
-
- describe '#changes' do
- it 'returns an array of Change objects' do
- expect(project_helper.changes).to all(be_an(Gitlab::Dangerfiles::Change))
- end
-
- it 'groups changes by change type' do
- changes = project_helper.changes
-
- expect(changes.added.files).to eq(added_files)
- expect(changes.modified.files).to eq(modified_files)
- expect(changes.deleted.files).to eq(deleted_files)
- expect(changes.renamed_before.files).to eq([renamed_before_file])
- expect(changes.renamed_after.files).to eq([renamed_after_file])
- end
+ allow(fake_helper).to receive(:config).and_return(double(files_to_category: described_class::CATEGORIES))
end
describe '#categories_for_file' do
@@ -86,7 +71,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'rubocop/foo' | [:backend]
'.rubocop.yml' | [:backend]
'.rubocop_todo.yml' | [:backend]
- '.rubocop_manual_todo.yml' | [:backend]
+ '.rubocop_todo/cop/name.yml' | [:backend]
'spec/foo' | [:backend]
'spec/foo/bar' | [:backend]
@@ -192,6 +177,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'spec/frontend/tracking_spec.js' | [:frontend, :product_intelligence]
'lib/gitlab/usage_database/foo.rb' | [:backend]
'config/metrics/counts_7d/test_metric.yml' | [:product_intelligence]
+ 'config/events/snowplow_event.yml' | [:product_intelligence]
'config/metrics/schema.json' | [:product_intelligence]
'doc/api/usage_data.md' | [:product_intelligence]
'spec/lib/gitlab/usage_data_spec.rb' | [:product_intelligence]
@@ -246,7 +232,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
end
with_them do
- subject { project_helper.categories_for_file(path) }
+ subject { project_helper.helper.categories_for_file(path) }
it { is_expected.to eq(expected_categories) }
end
@@ -274,7 +260,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
changed_files.each do |file|
allow(fake_git).to receive(:diff_for_file).with(file) { double(:diff, patch: patch) }
- expect(project_helper.categories_for_file(file)).to eq(expected_categories)
+ expect(project_helper.helper.categories_for_file(file)).to eq(expected_categories)
end
end
end
@@ -283,7 +269,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
describe '.local_warning_message' do
it 'returns an informational message with rules that can run' do
- expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation')
+ expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation')
end
end
@@ -320,93 +306,13 @@ RSpec.describe Tooling::Danger::ProjectHelper do
it 'returns all changed files starting with ee/' do
changes = double
- expect(project_helper).to receive(:changes).and_return(changes)
+ expect(fake_helper).to receive(:changes).and_return(changes)
expect(changes).to receive(:files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k])
is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb])
end
end
- describe '#project_name' do
- subject { project_helper.project_name }
-
- it 'returns gitlab if ee? returns true' do
- expect(project_helper).to receive(:ee?) { true }
-
- is_expected.to eq('gitlab')
- end
-
- it 'returns gitlab-ce if ee? returns false' do
- expect(project_helper).to receive(:ee?) { false }
-
- is_expected.to eq('gitlab-foss')
- end
- end
-
- describe '#ee?' do
- subject { project_helper.__send__(:ee?) }
-
- let(:ee_dir) { File.expand_path('../../../ee', __dir__) }
-
- context 'when ENV["CI_PROJECT_NAME"] is set' do
- before do
- stub_env('CI_PROJECT_NAME', ci_project_name)
- end
-
- context 'when ENV["CI_PROJECT_NAME"] is gitlab' do
- let(:ci_project_name) { 'gitlab' }
-
- it 'returns true' do
- is_expected.to eq(true)
- end
- end
-
- context 'when ENV["CI_PROJECT_NAME"] is gitlab-ee' do
- let(:ci_project_name) { 'gitlab-ee' }
-
- it 'returns true' do
- is_expected.to eq(true)
- end
- end
-
- context 'when ENV["CI_PROJECT_NAME"] is gitlab-foss' do
- let(:ci_project_name) { 'gitlab-foss' }
-
- it 'resolves to Dir.exist?' do
- expected = Dir.exist?(ee_dir)
-
- expect(Dir).to receive(:exist?).with(ee_dir).and_call_original
-
- is_expected.to eq(expected)
- end
- end
- end
-
- context 'when ENV["CI_PROJECT_NAME"] is absent' do
- before do
- stub_env('CI_PROJECT_NAME', nil)
-
- expect(Dir).to receive(:exist?).with(ee_dir).and_return(has_ee_dir)
- end
-
- context 'when ee/ directory exists' do
- let(:has_ee_dir) { true }
-
- it 'returns true' do
- is_expected.to eq(true)
- end
- end
-
- context 'when ee/ directory does not exist' do
- let(:has_ee_dir) { false }
-
- it 'returns false' do
- is_expected.to eq(false)
- end
- end
- end
- end
-
describe '#file_lines' do
let(:filename) { 'spec/foo_spec.rb' }
let(:file_spy) { spy }
diff --git a/spec/tooling/danger/specs_spec.rb b/spec/tooling/danger/specs_spec.rb
index a5978020c9d..b2454960a7b 100644
--- a/spec/tooling/danger/specs_spec.rb
+++ b/spec/tooling/danger/specs_spec.rb
@@ -3,7 +3,7 @@
require 'rspec-parameterized'
require 'gitlab-dangerfiles'
require 'danger'
-require 'danger/plugins/helper'
+require 'danger/plugins/internal/helper'
require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../tooling/danger/specs'
diff --git a/spec/tooling/graphql/docs/renderer_spec.rb b/spec/tooling/graphql/docs/renderer_spec.rb
index 1c9605304ff..18256fea2d6 100644
--- a/spec/tooling/graphql/docs/renderer_spec.rb
+++ b/spec/tooling/graphql/docs/renderer_spec.rb
@@ -438,12 +438,12 @@ RSpec.describe Tooling::Graphql::Docs::Renderer do
mutation.description 'Make everything very pretty.'
mutation.argument :prettiness_factor,
- type: GraphQL::FLOAT_TYPE,
+ type: GraphQL::Types::Float,
required: true,
description: 'How much prettier?'
mutation.argument :pulchritude,
- type: GraphQL::FLOAT_TYPE,
+ type: GraphQL::Types::Float,
required: false,
description: 'How much prettier?',
deprecated: {
diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb
index 94fa9d682e1..8a944a473d7 100644
--- a/spec/tooling/quality/test_level_spec.rb
+++ b/spec/tooling/quality/test_level_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a pattern' do
expect(subject.pattern(:unit))
- .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,spam,support_specs,tasks,uploaders,validators,views,workers,tooling}{,/**/}*_spec.rb")
+ .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling}{,/**/}*_spec.rb")
end
end
@@ -110,7 +110,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a regexp' do
expect(subject.regexp(:unit))
- .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|spam|support_specs|tasks|uploaders|validators|views|workers|tooling)})
+ .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling)})
end
end
diff --git a/spec/tooling/rspec_flaky/flaky_example_spec.rb b/spec/tooling/rspec_flaky/flaky_example_spec.rb
index ab652662c0b..03436ee1cbd 100644
--- a/spec/tooling/rspec_flaky/flaky_example_spec.rb
+++ b/spec/tooling/rspec_flaky/flaky_example_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'active_support/testing/time_helpers'
require_relative '../../support/helpers/stub_env'
+require_relative '../../support/time_travel'
require_relative '../../../tooling/rspec_flaky/flaky_example'
@@ -36,40 +36,39 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do
}
end
- let(:example) { OpenStruct.new(example_attrs) }
-
before do
# Stub these env variables otherwise specs don't behave the same on the CI
- stub_env('CI_PROJECT_URL', nil)
- stub_env('CI_JOB_ID', nil)
+ stub_env('CI_JOB_URL', nil)
end
- describe '#initialize' do
+ describe '#initialize', :freeze_time do
shared_examples 'a valid FlakyExample instance' do
let(:flaky_example) { described_class.new(args) }
it 'returns valid attributes' do
- expect(flaky_example.uid).to eq(flaky_example_attrs[:uid])
- expect(flaky_example.file).to eq(flaky_example_attrs[:file])
- expect(flaky_example.line).to eq(flaky_example_attrs[:line])
- expect(flaky_example.description).to eq(flaky_example_attrs[:description])
- expect(flaky_example.first_flaky_at).to eq(expected_first_flaky_at)
- expect(flaky_example.last_flaky_at).to eq(expected_last_flaky_at)
- expect(flaky_example.last_attempts_count).to eq(flaky_example_attrs[:last_attempts_count])
- expect(flaky_example.flaky_reports).to eq(expected_flaky_reports)
+ attrs = flaky_example.to_h
+
+ expect(attrs[:uid]).to eq(flaky_example_attrs[:uid])
+ expect(attrs[:file]).to eq(flaky_example_attrs[:file])
+ expect(attrs[:line]).to eq(flaky_example_attrs[:line])
+ expect(attrs[:description]).to eq(flaky_example_attrs[:description])
+ expect(attrs[:first_flaky_at]).to eq(expected_first_flaky_at)
+ expect(attrs[:last_flaky_at]).to eq(expected_last_flaky_at)
+ expect(attrs[:last_attempts_count]).to eq(flaky_example_attrs[:last_attempts_count])
+ expect(attrs[:flaky_reports]).to eq(expected_flaky_reports)
end
end
- context 'when given an Rspec::Example' do
+ context 'when given an Example hash' do
it_behaves_like 'a valid FlakyExample instance' do
- let(:args) { example }
- let(:expected_first_flaky_at) { nil }
- let(:expected_last_flaky_at) { nil }
+ let(:args) { example_attrs }
+ let(:expected_first_flaky_at) { Time.now }
+ let(:expected_last_flaky_at) { Time.now }
let(:expected_flaky_reports) { 0 }
end
end
- context 'when given a hash' do
+ context 'when given a FlakyExample hash' do
it_behaves_like 'a valid FlakyExample instance' do
let(:args) { flaky_example_attrs }
let(:expected_flaky_reports) { flaky_example_attrs[:flaky_reports] }
@@ -89,17 +88,17 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do
freeze_time do
flaky_example.update_flakiness!
- expect(flaky_example.first_flaky_at).to eq(Time.now)
+ expect(flaky_example.to_h[:first_flaky_at]).to eq(Time.now)
end
end
it 'maintains the first_flaky_at if exists' do
flaky_example.update_flakiness!
- expected_first_flaky_at = flaky_example.first_flaky_at
+ expected_first_flaky_at = flaky_example.to_h[:first_flaky_at]
travel_to(Time.now + 42) do
flaky_example.update_flakiness!
- expect(flaky_example.first_flaky_at).to eq(expected_first_flaky_at)
+ expect(flaky_example.to_h[:first_flaky_at]).to eq(expected_first_flaky_at)
end
end
@@ -108,53 +107,54 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do
the_future = Time.now
flaky_example.update_flakiness!
- expect(flaky_example.last_flaky_at).to eq(the_future)
+ expect(flaky_example.to_h[:last_flaky_at]).to eq(the_future)
end
end
it 'updates the flaky_reports' do
- expected_flaky_reports = flaky_example.first_flaky_at ? flaky_example.flaky_reports + 1 : 1
+ expected_flaky_reports = flaky_example.to_h[:first_flaky_at] ? flaky_example.to_h[:flaky_reports] + 1 : 1
- expect { flaky_example.update_flakiness! }.to change { flaky_example.flaky_reports }.by(1)
- expect(flaky_example.flaky_reports).to eq(expected_flaky_reports)
+ expect { flaky_example.update_flakiness! }.to change { flaky_example.to_h[:flaky_reports] }.by(1)
+ expect(flaky_example.to_h[:flaky_reports]).to eq(expected_flaky_reports)
end
context 'when passed a :last_attempts_count' do
it 'updates the last_attempts_count' do
flaky_example.update_flakiness!(last_attempts_count: 42)
- expect(flaky_example.last_attempts_count).to eq(42)
+ expect(flaky_example.to_h[:last_attempts_count]).to eq(42)
end
end
context 'when run on the CI' do
+ let(:job_url) { 'https://gitlab.com/gitlab-org/gitlab-foss/-/jobs/42' }
+
before do
- stub_env('CI_PROJECT_URL', 'https://gitlab.com/gitlab-org/gitlab-foss')
- stub_env('CI_JOB_ID', 42)
+ stub_env('CI_JOB_URL', job_url)
end
it 'updates the last_flaky_job' do
flaky_example.update_flakiness!
- expect(flaky_example.last_flaky_job).to eq('https://gitlab.com/gitlab-org/gitlab-foss/-/jobs/42')
+ expect(flaky_example.to_h[:last_flaky_job]).to eq(job_url)
end
end
end
- context 'when given an Rspec::Example' do
+ context 'when given an Example hash' do
it_behaves_like 'an up-to-date FlakyExample instance' do
- let(:args) { example }
+ let(:args) { example_attrs }
end
end
- context 'when given a hash' do
+ context 'when given a FlakyExample hash' do
it_behaves_like 'an up-to-date FlakyExample instance' do
let(:args) { flaky_example_attrs }
end
end
end
- describe '#to_h' do
+ describe '#to_h', :freeze_time do
shared_examples 'a valid FlakyExample hash' do
let(:additional_attrs) { {} }
@@ -166,17 +166,17 @@ RSpec.describe RspecFlaky::FlakyExample, :aggregate_failures do
end
end
- context 'when given an Rspec::Example' do
- let(:args) { example }
+ context 'when given an Example hash' do
+ let(:args) { example_attrs }
it_behaves_like 'a valid FlakyExample hash' do
let(:additional_attrs) do
- { first_flaky_at: nil, last_flaky_at: nil, last_flaky_job: nil, flaky_reports: 0 }
+ { first_flaky_at: Time.now, last_flaky_at: Time.now, last_flaky_job: nil, flaky_reports: 0 }
end
end
end
- context 'when given a hash' do
+ context 'when given a FlakyExample hash' do
let(:args) { flaky_example_attrs }
it_behaves_like 'a valid FlakyExample hash'
diff --git a/spec/tooling/rspec_flaky/flaky_examples_collection_spec.rb b/spec/tooling/rspec_flaky/flaky_examples_collection_spec.rb
index 823459e31b4..e5f985c9596 100644
--- a/spec/tooling/rspec_flaky/flaky_examples_collection_spec.rb
+++ b/spec/tooling/rspec_flaky/flaky_examples_collection_spec.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true
+require_relative '../../support/time_travel'
+
require_relative '../../../tooling/rspec_flaky/flaky_examples_collection'
-RSpec.describe RspecFlaky::FlakyExamplesCollection, :aggregate_failures do
+RSpec.describe RspecFlaky::FlakyExamplesCollection, :aggregate_failures, :freeze_time do
let(:collection_hash) do
{
a: { example_id: 'spec/foo/bar_spec.rb:2' },
@@ -14,15 +16,19 @@ RSpec.describe RspecFlaky::FlakyExamplesCollection, :aggregate_failures do
{
a: {
example_id: 'spec/foo/bar_spec.rb:2',
- first_flaky_at: nil,
- last_flaky_at: nil,
- last_flaky_job: nil
+ first_flaky_at: Time.now,
+ last_flaky_at: Time.now,
+ last_flaky_job: nil,
+ flaky_reports: 0,
+ last_attempts_count: nil
},
b: {
example_id: 'spec/foo/baz_spec.rb:3',
- first_flaky_at: nil,
- last_flaky_at: nil,
- last_flaky_job: nil
+ first_flaky_at: Time.now,
+ last_flaky_at: Time.now,
+ last_flaky_job: nil,
+ flaky_reports: 0,
+ last_attempts_count: nil
}
}
end
@@ -59,9 +65,11 @@ RSpec.describe RspecFlaky::FlakyExamplesCollection, :aggregate_failures do
expect((collection2 - collection1).to_h).to eq(
c: {
example_id: 'spec/bar/baz_spec.rb:4',
- first_flaky_at: nil,
- last_flaky_at: nil,
- last_flaky_job: nil
+ first_flaky_at: Time.now,
+ last_flaky_at: Time.now,
+ last_flaky_job: nil,
+ flaky_reports: 0,
+ last_attempts_count: nil
})
end
diff --git a/spec/tooling/rspec_flaky/listener_spec.rb b/spec/tooling/rspec_flaky/listener_spec.rb
index 429724a20cf..51a815dafbf 100644
--- a/spec/tooling/rspec_flaky/listener_spec.rb
+++ b/spec/tooling/rspec_flaky/listener_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'active_support/testing/time_helpers'
require_relative '../../support/helpers/stub_env'
+require_relative '../../support/time_travel'
require_relative '../../../tooling/rspec_flaky/listener'
@@ -53,8 +53,7 @@ RSpec.describe RspecFlaky::Listener, :aggregate_failures do
before do
# Stub these env variables otherwise specs don't behave the same on the CI
- stub_env('CI_PROJECT_URL', nil)
- stub_env('CI_JOB_ID', nil)
+ stub_env('CI_JOB_URL', nil)
stub_env('SUITE_FLAKY_RSPEC_REPORT_PATH', nil)
end
@@ -217,7 +216,7 @@ RSpec.describe RspecFlaky::Listener, :aggregate_failures do
expect(RspecFlaky::Report).to receive(:new).with(listener.flaky_examples).and_return(report1)
expect(report1).to receive(:write).with(RspecFlaky::Config.flaky_examples_report_path)
- expect(RspecFlaky::Report).to receive(:new).with(listener.flaky_examples - listener.suite_flaky_examples).and_return(report2)
+ expect(RspecFlaky::Report).to receive(:new).with(listener.__send__(:new_flaky_examples)).and_return(report2)
expect(report2).to receive(:write).with(RspecFlaky::Config.new_flaky_examples_report_path)
listener.dump_summary(nil)
diff --git a/spec/tooling/rspec_flaky/report_spec.rb b/spec/tooling/rspec_flaky/report_spec.rb
index 6c364cd5cd3..ffd0cd987aa 100644
--- a/spec/tooling/rspec_flaky/report_spec.rb
+++ b/spec/tooling/rspec_flaky/report_spec.rb
@@ -2,9 +2,11 @@
require 'tempfile'
+require_relative '../../support/time_travel'
+
require_relative '../../../tooling/rspec_flaky/report'
-RSpec.describe RspecFlaky::Report, :aggregate_failures do
+RSpec.describe RspecFlaky::Report, :aggregate_failures, :freeze_time do
let(:thirty_one_days) { 3600 * 24 * 31 }
let(:collection_hash) do
{