2019-08-22 06:57:44 -04:00
# frozen_string_literal: true
2021-02-23 04:10:45 -05:00
require 'rspec-parameterized'
require_relative '../../support/helpers/stub_env'
require_relative '../../../tooling/rspec_flaky/config'
2017-10-05 09:59:58 -04:00
2020-06-24 14:09:03 -04:00
RSpec . describe RspecFlaky :: Config , :aggregate_failures do
2021-02-23 04:10:45 -05:00
include StubENV
2017-10-05 09:59:58 -04:00
before do
# Stub these env variables otherwise specs don't behave the same on the CI
stub_env ( 'FLAKY_RSPEC_GENERATE_REPORT' , nil )
2022-01-25 13:11:55 -05:00
stub_env ( 'FLAKY_RSPEC_SUITE_REPORT_PATH' , nil )
2017-10-05 09:59:58 -04:00
stub_env ( 'FLAKY_RSPEC_REPORT_PATH' , nil )
stub_env ( 'NEW_FLAKY_RSPEC_REPORT_PATH' , nil )
2022-01-25 13:11:55 -05:00
stub_env ( 'SKIPPED_FLAKY_TESTS_REPORT_PATH' , nil )
2021-02-23 04:10:45 -05:00
# Ensure the behavior is the same locally and on CI (where Rails is defined since we run this test as part of the whole suite), i.e. Rails isn't defined
allow ( described_class ) . to receive ( :rails_path ) . and_wrap_original do | method , path |
path
end
2017-10-05 09:59:58 -04:00
end
describe '.generate_report?' do
context " when ENV['FLAKY_RSPEC_GENERATE_REPORT'] is not set " do
it 'returns false' do
expect ( described_class ) . not_to be_generate_report
end
end
2018-04-10 07:22:19 -04:00
context " when ENV['FLAKY_RSPEC_GENERATE_REPORT'] is set " do
using RSpec :: Parameterized :: TableSyntax
2017-10-05 09:59:58 -04:00
2018-04-10 07:22:19 -04:00
where ( :env_value , :result ) do
'1' | true
'true' | true
'foo' | false
'0' | false
'false' | false
2017-10-05 09:59:58 -04:00
end
2018-04-10 07:22:19 -04:00
with_them do
before do
stub_env ( 'FLAKY_RSPEC_GENERATE_REPORT' , env_value )
end
2017-10-05 09:59:58 -04:00
2018-04-10 07:22:19 -04:00
it 'returns false' do
expect ( described_class . generate_report? ) . to be ( result )
end
2017-10-05 09:59:58 -04:00
end
end
end
describe '.suite_flaky_examples_report_path' do
2022-01-25 13:11:55 -05:00
context " when ENV['FLAKY_RSPEC_SUITE_REPORT_PATH'] is not set " do
2017-10-05 09:59:58 -04:00
it 'returns the default path' do
2022-01-25 13:11:55 -05:00
expect ( described_class . suite_flaky_examples_report_path ) . to eq ( 'rspec/flaky/suite-report.json' )
2017-10-05 09:59:58 -04:00
end
end
2022-01-25 13:11:55 -05:00
context " when ENV['FLAKY_RSPEC_SUITE_REPORT_PATH'] is set " do
2017-10-05 09:59:58 -04:00
before do
2022-01-25 13:11:55 -05:00
stub_env ( 'FLAKY_RSPEC_SUITE_REPORT_PATH' , 'foo/suite-report.json' )
2017-10-05 09:59:58 -04:00
end
it 'returns the value of the env variable' do
expect ( described_class . suite_flaky_examples_report_path ) . to eq ( 'foo/suite-report.json' )
end
end
end
describe '.flaky_examples_report_path' do
context " when ENV['FLAKY_RSPEC_REPORT_PATH'] is not set " do
it 'returns the default path' do
2022-01-25 13:11:55 -05:00
expect ( described_class . flaky_examples_report_path ) . to eq ( 'rspec/flaky/report.json' )
2017-10-05 09:59:58 -04:00
end
end
context " when ENV['FLAKY_RSPEC_REPORT_PATH'] is set " do
before do
stub_env ( 'FLAKY_RSPEC_REPORT_PATH' , 'foo/report.json' )
end
it 'returns the value of the env variable' do
expect ( described_class . flaky_examples_report_path ) . to eq ( 'foo/report.json' )
end
end
end
describe '.new_flaky_examples_report_path' do
context " when ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] is not set " do
it 'returns the default path' do
2022-01-25 13:11:55 -05:00
expect ( described_class . new_flaky_examples_report_path ) . to eq ( 'rspec/flaky/new-report.json' )
2017-10-05 09:59:58 -04:00
end
end
context " when ENV['NEW_FLAKY_RSPEC_REPORT_PATH'] is set " do
before do
stub_env ( 'NEW_FLAKY_RSPEC_REPORT_PATH' , 'foo/new-report.json' )
end
it 'returns the value of the env variable' do
expect ( described_class . new_flaky_examples_report_path ) . to eq ( 'foo/new-report.json' )
end
end
end
2022-01-25 13:11:55 -05:00
describe '.skipped_flaky_tests_report_path' do
context " when ENV['SKIPPED_FLAKY_TESTS_REPORT_PATH'] is not set " do
it 'returns the default path' do
expect ( described_class . skipped_flaky_tests_report_path ) . to eq ( 'rspec/flaky/skipped_flaky_tests_report.txt' )
end
end
context " when ENV['SKIPPED_FLAKY_TESTS_REPORT_PATH'] is set " do
before do
stub_env ( 'SKIPPED_FLAKY_TESTS_REPORT_PATH' , 'foo/skipped_flaky_tests_report.txt' )
end
it 'returns the value of the env variable' do
expect ( described_class . skipped_flaky_tests_report_path ) . to eq ( 'foo/skipped_flaky_tests_report.txt' )
end
end
end
2017-10-05 09:59:58 -04:00
end