Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Created May 18, 2024 18:47
Show Gist options
  • Save barelyknown/a597f500bf0655153c44576dfa427bf6 to your computer and use it in GitHub Desktop.
Save barelyknown/a597f500bf0655153c44576dfa427bf6 to your computer and use it in GitHub Desktop.
This script identifies changed spec files in a Git repository and runs RSpec tests on them.
#!/bin/zsh
# Step 1: Get the list of changed files
changed_files=$(git diff --name-only master)
# Step 2: Initialize an array for spec files
spec_files=()
# Step 3: Populate the array with spec files
while IFS= read -r file; do
spec_files+=("$file")
done < <(echo "$changed_files" | grep -E '_spec\.rb$' | grep -E '^spec/')
# Step 4: Run RSpec on the filtered spec files
bin/rspec "${spec_files[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment