Skip to content

Instantly share code, notes, and snippets.

@shayani
Last active March 29, 2024 18:44
Show Gist options
  • Save shayani/c4fd6c427f932ab9fe3e98185a912e61 to your computer and use it in GitHub Desktop.
Save shayani/c4fd6c427f932ab9fe3e98185a912e61 to your computer and use it in GitHub Desktop.
Run RSpec only on changed/created `*_spec.rb` files from current agains target branch
#!/bin/bash
# Set default branch name
branch_name="${1:-staging}"
# Get changed files with grep for _spec.rb extension
changed_specs=$(git diff --name-only --diff-filter=d "$branch_name" | grep _spec.rb)
# Check if any changed specs found
if [[ -z "$changed_specs" ]]; then
echo "No changed _spec.rb files found between HEAD and $branch_name."
exit 0
fi
echo "List of changed spec files:"
echo "$changed_specs"
# Run rspec with all changed specs
bundle exec rspec --format documentation $changed_specs
echo "RSpec tests completed for changed _spec.rb files."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment