Module: Quarantine::RSpecAdapter
- Extended by:
- T::Sig
- Defined in:
- lib/quarantine/rspec_adapter.rb
Class Method Summary collapse
- .bind ⇒ Object
- .bind_fetch_test_statuses ⇒ Object
- .bind_logger ⇒ Object
- .bind_record_tests ⇒ Object
- .bind_rspec_configurations ⇒ Object
- .bind_upload_tests ⇒ Object
- .quarantine ⇒ Object
Class Method Details
.bind ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/quarantine/rspec_adapter.rb', line 11 def self.bind bind_rspec_configurations bind_fetch_test_statuses bind_record_tests bind_upload_tests bind_logger end |
.bind_fetch_test_statuses ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/quarantine/rspec_adapter.rb', line 47 def self.bind_fetch_test_statuses ::RSpec.configure do |config| config.before(:suite) do Quarantine::RSpecAdapter.quarantine.fetch_test_statuses end end end |
.bind_logger ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/quarantine/rspec_adapter.rb', line 98 def self.bind_logger ::RSpec.configure do |config| config.after(:suite) do if RSpec.configuration.quarantine_logging RSpec.configuration.reporter.(Quarantine::RSpecAdapter.quarantine.summary) end end end end |
.bind_record_tests ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/quarantine/rspec_adapter.rb', line 57 def self.bind_record_tests ::RSpec.configure do |config| config.after(:each) do |example| = example. # optionally, the upstream RSpec configuration could define an after hook that marks an example as flaky in # the example's metadata quarantined = Quarantine::RSpecAdapter.quarantine.test_quarantined?(example) || [:flaky] if example.exception if [:retry_attempts] + 1 == [:retry] # will record the failed test if it's final retry from the rspec-retry gem if RSpec.configuration.skip_quarantined_tests && quarantined example.clear_exception! Quarantine::RSpecAdapter.quarantine.record_test(example, :quarantined, passed: false) else Quarantine::RSpecAdapter.quarantine.record_test(example, :failing, passed: false) end end elsif [:retry_attempts] > 0 # will record the flaky test if it failed the first run but passed a subsequent run Quarantine::RSpecAdapter.quarantine.record_test(example, :quarantined, passed: false) elsif quarantined Quarantine::RSpecAdapter.quarantine.record_test(example, :quarantined, passed: true) else Quarantine::RSpecAdapter.quarantine.record_test(example, :passing, passed: true) end end end end |
.bind_rspec_configurations ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/quarantine/rspec_adapter.rb', line 32 def self.bind_rspec_configurations ::RSpec.configure do |config| config.add_setting(:quarantine_database, default: { type: :dynamodb, region: 'us-west-1' }) config.add_setting(:quarantine_test_statuses, { default: 'test_statuses' }) config.add_setting(:skip_quarantined_tests, { default: true }) config.add_setting(:quarantine_record_tests, { default: true }) config.add_setting(:quarantine_logging, { default: true }) config.add_setting(:quarantine_extra_attributes) config.add_setting(:quarantine_failsafe_limit, default: 10) config.add_setting(:quarantine_release_at_consecutive_passes) end end |
.bind_upload_tests ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/quarantine/rspec_adapter.rb', line 88 def self.bind_upload_tests ::RSpec.configure do |config| config.after(:suite) do Quarantine::RSpecAdapter.quarantine.upload_tests if RSpec.configuration.quarantine_record_tests end end end |
.quarantine ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/quarantine/rspec_adapter.rb', line 20 def self.quarantine @quarantine = T.let(@quarantine, T.nilable(Quarantine)) @quarantine ||= Quarantine.new( database: RSpec.configuration.quarantine_database, test_statuses_table_name: RSpec.configuration.quarantine_test_statuses, extra_attributes: RSpec.configuration.quarantine_extra_attributes, failsafe_limit: RSpec.configuration.quarantine_failsafe_limit ) end |