Skip to content

Instantly share code, notes, and snippets.

@pivotal-chorus
Created April 22, 2013 17:39
Show Gist options
  • Save pivotal-chorus/5437004 to your computer and use it in GitHub Desktop.
Save pivotal-chorus/5437004 to your computer and use it in GitHub Desktop.
Run Jasmine specs from RubyMine. Create the shell script below as an external tool in RubyMine then bind it to a key.
#!/bin/sh
JASMINE_URL="http://localhost:8888/?spec="
if [ -z "$1" ]; then
echo "Opening $JASMINE_URL to run all the tests"
open "$JASMINE_URL"
exit 0
fi
# is this a spec file?
echo $1 | grep 'spec.js$'
if [ $? -eq 0 ]; then
# ends with 'spec.js', probably a spec file
SPECFILE=$1
else
# inject _spec and find the file with the right name
SPECFILE=$(find ./ofbiz/hot-deploy/client/spec -type f -iname $(basename $1 | sed 's/.js$/_spec.js/'))
if [ -z "$SPECFILE" ]; then
echo "Could not locate a spec file to go with $1" >&2
exit 1
fi
echo "Detected $SPECFILE as matching spec for $1"
fi
DESCRIBE_LINE=$(grep describe $SPECFILE | head -n1)
if [ -z "$DESCRIBE_LINE" ]; then
echo "This does not appear to be a spec file." >&2
exit 1
fi
# to escape the single quotes in sed, you do: '\'' - escaping your single quotes, and wrapping that in single quotes
# see: http://muffinresearch.co.uk/archives/2007/01/30/bash-single-quotes-inside-of-single-quoted-strings/
SPEC=$(echo $DESCRIBE_LINE | sed 's/.*["'\'']\(.*\)["'\''][^"'\'']*$/\1/')
echo "Opening $JASMINE_URL$SPEC"
open "$JASMINE_URL$SPEC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment