Module: CapyDash::RSpecIntegration
- Defined in:
- lib/capydash/rspec_integration.rb
Class Method Summary collapse
- .finish_test_run ⇒ Object
- .record_example(example) ⇒ Object
- .setup! ⇒ Object
- .start_test_run ⇒ Object
Class Method Details
.finish_test_run ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/capydash/rspec_integration.rb', line 88 def finish_test_run return unless @run_id return if @results.empty? # Calculate summary statistics total_tests = @results.length passed_tests = @results.count { |r| r[:steps].any? { |s| s[:status] == 'passed' } } failed_tests = @results.count { |r| r[:steps].any? { |s| s[:status] == 'failed' } } pending_tests = @results.count { |r| r[:steps].any? { |s| s[:status] == 'pending' } } # Create run data structure matching Minitest format run_data = { id: @run_id, created_at: @started_at.iso8601, total_tests: total_tests, passed_tests: passed_tests, failed_tests: failed_tests, tests: @results.map { |r| { test_name: r[:test_name], steps: r[:steps] } } } # Save using the existing persistence layer CapyDash.save_test_run(run_data) # Generate report generate_report(run_data) # Clear state @run_id = nil @results = [] end |
.record_example(example) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 86 |
# File 'lib/capydash/rspec_integration.rb', line 38 def record_example(example) return unless @run_id execution_result = example.execution_result # Map RSpec status to our status format status = case execution_result.status.to_s when 'passed' 'passed' when 'failed' 'failed' when 'pending' 'pending' else 'unknown' end # Extract error message if test failed = nil if execution_result.status == :failed && execution_result.exception = format_exception(execution_result.exception) end # Extract class name from example location # RSpec examples are typically in files like spec/features/user_spec.rb # We'll use the file path to determine the "class" name file_path = example.[:file_path] || '' class_name = extract_class_name_from_path(file_path) # Create test data structure matching Minitest format test_data = { test_name: "#{class_name}##{example.full_description}", steps: [ { step_name: 'test_execution', detail: example.full_description, status: status, error: } ] } # Add location information if example.[:location] test_data[:location] = example.[:location] end @results << test_data end |
.setup! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/capydash/rspec_integration.rb', line 9 def setup! return unless defined?(RSpec) return if @configured @results = [] @run_id = nil @configured = true RSpec.configure do |config| config.before(:suite) do CapyDash::RSpecIntegration.start_test_run end config.after(:each) do |example| CapyDash::RSpecIntegration.record_example(example) end config.after(:suite) do CapyDash::RSpecIntegration.finish_test_run end end end |
.start_test_run ⇒ Object
32 33 34 35 36 |
# File 'lib/capydash/rspec_integration.rb', line 32 def start_test_run @run_id = generate_run_id @results = [] @started_at = Time.now end |