Skip to content

Commit

Permalink
(CAT-1807) Remove all reference of analytics from the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
david22swan committed Apr 12, 2024
1 parent 64cc040 commit 9a2a96f
Show file tree
Hide file tree
Showing 24 changed files with 17 additions and 1,324 deletions.
21 changes: 0 additions & 21 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
# automatically load any shared examples or contexts
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }

analytics_config = nil

FIXTURES_DIR = File.join(__dir__, 'fixtures')
EMPTY_MODULE_ROOT = File.join(FIXTURES_DIR, 'module_root')

Expand All @@ -40,39 +38,20 @@
end
end

RSpec.shared_context 'stubbed analytics' do
let(:analytics) { PDK::Analytics::Client::Noop.new(logger: logger) }

before do |example|
allow(PDK).to receive(:analytics).and_return(analytics) if example.metadata[:use_stubbed_analytics]
end
end

RSpec.configure do |c|
c.define_derived_metadata do |metadata|
metadata[:use_stubbed_logger] = true unless metadata.key?(:use_stubbed_logger)
metadata[:use_stubbed_analytics] = true unless metadata.key?(:use_stubbed_analytics)
end

c.include_context 'stubbed logger'
c.include_context 'stubbed analytics'

c.before(:suite) do
require 'yaml'
analytics_config = Tempfile.new('analytics.yml')
analytics_config.write(YAML.dump(disabled: true))
analytics_config.close
ENV['PDK_ANALYTICS_CONFIG'] = analytics_config.path
end

c.after(:suite) do
analytics_config.unlink
end

# This should catch any tests where we are not mocking out the actual calls to Rubygems.org
c.before do
allow(Gem::SpecFetcher).to receive(:fetcher).and_raise('Unmocked call to Gem::SpecFetcher.fetcher!')
ENV['PDK_DISABLE_ANALYTICS'] = 'true'
end

c.add_setting :root
Expand Down
6 changes: 1 addition & 5 deletions spec/support/mock_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
RSpec.shared_context 'mock configuration' do
let(:default_answer_file_content) { nil }
let(:system_answers_content) { nil }
let(:analytics_config_content) { nil }
let(:user_config_content) { nil }
let(:system_config_content) { nil }
let(:bolt_analytics_content) { nil }

let(:new_config) do
PDK::Config.new.tap do |item|
Expand All @@ -23,10 +21,8 @@
[
{ file: PDK::AnswerFile.default_answer_file_path, content: default_answer_file_content },
{ file: PDK::Config.system_answers_path, content: system_answers_content },
{ file: PDK::Config.analytics_config_path, content: analytics_config_content },
{ file: PDK::Config.user_config_path, content: user_config_content },
{ file: PDK::Config.system_config_path, content: system_config_content },
{ file: '~/.puppetlabs/bolt/analytics.yaml', content: bolt_analytics_content }
{ file: PDK::Config.system_config_path, content: system_config_content }
].each do |item|
# If the content is nil then mock a missing file, otherwise mock a read-able file
if item[:content].nil?
Expand Down
103 changes: 0 additions & 103 deletions spec/unit/pdk/analytics/client/google_analytics_spec.rb

This file was deleted.

38 changes: 0 additions & 38 deletions spec/unit/pdk/analytics/client/noop_spec.rb

This file was deleted.

55 changes: 0 additions & 55 deletions spec/unit/pdk/analytics/util_spec.rb

This file was deleted.

57 changes: 0 additions & 57 deletions spec/unit/pdk/analytics_spec.rb

This file was deleted.

Loading

0 comments on commit 9a2a96f

Please sign in to comment.