Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
safafa committed Jan 18, 2024
1 parent 819e3a5 commit b779a92
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
test:
name: Test failing spec detector
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ci_node_total: [3]
ci_node_index: [0, 1, 2]

steps:
- uses: actions/checkout@v3
Expand All @@ -22,17 +27,21 @@ jobs:
- name: Lint files
run: bundle exec rake rubocop
- name: Run tests
env:
RAILS_ENV: test
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: bundle exec rake spec
- name: Upload Failures
uses: actions/upload-artifact@v3
with:
name: Failures
path: failures_log_*.yml
path: spec/failing_spec_detector/failures
- name: Upload Exceptions
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v2
with:
name: Exceptions
path: exceptions_log_*.yml
path: spec/failing_spec_detector/exceptions

print_log:
name: Test print logs task
Expand All @@ -50,10 +59,12 @@ jobs:
uses: actions/download-artifact@v3
with:
name: Failures
path: spec/failing_spec_detector/failures
- name: Download Exceptions
uses: actions/download-artifact@v3
with:
name: Exceptions
path: spec/failing_spec_detector/exceptions
- name: Run print_log task
run: bundle exec rake failing_specs_detector:print_log

8 changes: 6 additions & 2 deletions lib/failing_spec_detector/failing_spec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rspec/core/formatters/base_text_formatter'
require_relative 'failure'
require 'yaml'
require 'fileutils'

module FailingSpecDetector
class FailingSpecFormatter < RSpec::Core::Formatters::BaseTextFormatter
Expand All @@ -12,8 +13,9 @@ def initialize(output)
super(output)
@failures = []
@exceptions = []
@failures_filename = "failures_log_#{ENV.fetch('TEST_ENV_NUMBER', nil)}.yml"
@exceptions_filename = "exceptions_log_#{ENV.fetch('TEST_ENV_NUMBER', nil)}.yml"
@failures_filename = "spec/failing_spec_detector/failures/failures_log_#{ENV.fetch('TEST_ENV_NUMBER', nil)}.yml"
@exceptions_filename = "spec/failing_spec_detector/exceptions/exceptions_log_#{ENV.fetch('TEST_ENV_NUMBER',
nil)}.yml"
end

def example_failed(failure)
Expand All @@ -27,6 +29,8 @@ def example_failed(failure)
end

def stop(_notification)
FileUtils.mkdir_p 'spec/failing_spec_detector/failures'
FileUtils.mkdir_p 'spec/failing_spec_detector/exceptions'
File.write(@exceptions_filename, YAML.dump(@exceptions), mode: 'w')
File.write(@failures_filename, YAML.dump(@failures), mode: 'w')
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/failing_spec_detector/print_log.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace :failing_specs_detector do
task :print_log do
failures = []
exceptions = []
failures_file_paths = Dir['failures_log_*.yml']
exceptions_file_paths = Dir['exceptions_log_*.yml']
failures_file_paths = Dir['spec/failing_spec_detector/failures/failures_log_*.yml']
exceptions_file_paths = Dir['spec/failing_spec_detector/exceptions/exceptions_log_*.yml']
failures_file_paths.each do |file_path|
failures.concat(YAML.load_file(file_path, permitted_classes: [FailingSpecDetector::Failure]))
File.delete(file_path)
Expand Down
4 changes: 2 additions & 2 deletions spec/failing_spec_detector/failing_spec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
let(:output) { Tempfile.new('./output_to_close') }
let(:expected_failures_file_path) { './spec/support/expected_failures_log_.yml' }
let(:expected_exceptions_file_path) { './spec/support/expected_exceptions_log_.yml' }
let(:actual_failures_file_path) { './failures_log_.yml' }
let(:actual_exceptions_file_path) { './exceptions_log_.yml' }
let(:actual_failures_file_path) { './spec/failing_spec_detector/failures/failures_log_.yml' }
let(:actual_exceptions_file_path) { './spec/failing_spec_detector/exceptions/exceptions_log_.yml' }
let(:expected_failures_file) { File.new(expected_failures_file_path, 'r') }
let(:expected_exceptions_file) { File.new(expected_exceptions_file_path, 'r') }
let(:actual_failures_file) { File.new(actual_failures_file_path, 'r') }
Expand Down

0 comments on commit b779a92

Please sign in to comment.