Skip to content

Commit

Permalink
Add script that aids in debugging
Browse files Browse the repository at this point in the history
Update spec that's failing
  • Loading branch information
jasonhoc committed Apr 8, 2024
1 parent cf9f579 commit e29ecef
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions modules/mobile/lib/scripts/parse_rspec_xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'nokogiri'

Check failure on line 1 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/FrozenStringLiteralComment: Missing frozen string literal comment.
require 'optparse'

def extract_xml_attributes(file_path, mode)

Check failure on line 4 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Metrics/MethodLength: Method has too many lines. [26/20]
begin

Check failure on line 5 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/RedundantBegin: Redundant `begin` block detected.
# Load XML content from the file
xml_content = File.read(file_path)

# Parse XML content using Nokogiri
doc = Nokogiri::XML(xml_content)

# Extract attributes from XML nodes
seed = nil
files = []
doc.traverse do |node|
if node['name'] == 'seed'

Check failure on line 16 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/IfUnlessModifier: Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`.
seed = node.attributes['value'].value
end

if node.element? && node.attributes['file']
case mode
when 'errors'
if node.children.any? { |child| child.name == 'failure' }
file_path = node.attributes['file'].value
files << (file_path.start_with?('/') ? ".#{file_path}" : file_path)

Check failure on line 25 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Metrics/BlockNesting: Avoid more than 3 levels of block nesting.
end
when 'full'
file_path = node.attributes['file'].value
files << (file_path.start_with?('/') ? ".#{file_path}" : file_path)
end
end
end

# Flatten the array of attributes and join them into a string
"bundle exec rspec --seed #{seed} --bisect #{files.uniq.join(' ')}"
rescue StandardError => e

Check failure on line 36 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/RescueStandardError: Omit the error class when rescuing `StandardError` by itself.
puts "Error: #{e.message}"
end
end

options = {}

OptionParser.new do |opts|
opts.banner = "Usage: ruby extract_xml_attributes.rb [options] FILE_PATH"

Check failure on line 44 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
opts.on("-m", "--mode MODE", "Mode: full or errors (default: errors)") do |m|

Check failure on line 45 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check failure on line 45 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check failure on line 45 in modules/mobile/lib/scripts/parse_rspec_xml.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
options[:mode] = m.downcase
end
end.parse!

file_path = ARGV.join(' ')

# Check if file path is provided
if file_path.nil?
puts "Error: File path is required."
puts "Usage: ruby script.rb [options] FILE_PATH"
exit(1)
end

# Set default mode to 'errors' if mode is not specified
mode = options[:mode] || "errors"

# Call the method to extract XML attributes
xml_attributes = extract_xml_attributes(file_path, mode)

# Output the XML attributes
puts "\nRun the following commands in vets-api in order to debug:\n\n#{xml_attributes}"
1 change: 1 addition & 0 deletions modules/mobile/spec/request/v1/user_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

context 'with no upstream errors' do
before do
Flipper.enable('va_online_scheduling')
VCR.use_cassette('mobile/payment_information/payment_information') do
VCR.use_cassette('mobile/user/get_facilities') do
VCR.use_cassette('mobile/va_profile/demographics/demographics') do
Expand Down

0 comments on commit e29ecef

Please sign in to comment.