Created
February 17, 2025 16:25
-
-
Save donnfelker/bbb25e1d578201e604494638f93166a2 to your computer and use it in GitHub Desktop.
run_test - a shell script function that allows you to quickly run rails tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allows you to run a rails test from the CLI with: | |
# | |
# run_test "when x happens then abcd should happen" | |
# | |
# Which turns it into: | |
# rails test --name "/^test_when_x_happens_then_abcd_should_happen$/" | |
# | |
run_test() { | |
# Check if a test description was provided | |
if [ -z "$1" ]; then | |
echo "Usage: run_test \"test description\"" | |
return 1 | |
fi | |
# Convert spaces to underscores | |
local transformed=$(echo "$1" | sed 's/ /_/g') | |
# Build the regex. Adjust the prefix if necessary. | |
local regex="^test_${transformed}\$" | |
# Run the rails test command | |
rails test --name "/${regex}/" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment