Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonm23/6f6ea50c1d3dbfd484a2 to your computer and use it in GitHub Desktop.
Save jasonm23/6f6ea50c1d3dbfd484a2 to your computer and use it in GitHub Desktop.
(defun jasmine-coffee/verify-thing (pattern)
"Compose and launch a jasmine spec URL for the thing defined by PATTERN."
(let* ((start-column 0) (spec-string ""))
(save-excursion
(move-end-of-line 1)
(re-search-backward pattern)
(setq start-column (current-column))
(setq spec-string (match-string-no-properties 1))
(while
(re-search-backward jasmine-coffee/describe-regexp 0 t)
(when (< (current-column) start-column)
(setq start-column (current-column))
(setq spec-string (format "%s %s" (match-string 1) spec-string)))))
(setq spec-string (replace-regexp-in-string "#" "%23" spec-string))
(save-current-buffer)
(browse-url (url-encode-url (concat jasmine-coffee/base-url spec-string)))))

Steps.

  1. move to the end of the current line,
  2. search backwards for the thing/pattern
  3. set the start-column to the current column.
  4. set the spec-string to the subgroup match on description of thing/pattern (ie. the text enclosed in quotes)
  5. while you can search backwards for a describe block and get a match:
  6. while the current-colum < start-column 1. set the start-column to match the current-column 2. add the found description to the front of the spec-string
  7. replace '#' with %23 in the spec-string
  8. save the buffer in case of changes
  9. url encode the spec-string
  10. browse the jasmine url + encoded spec string
@jasonm23
Copy link
Author

jasonm23 commented Aug 7, 2014

Finding a describe.

/^\s*describe[( ] *['\"](.*)['\"]\\)? *,/

finding an it.

/^\s*it[( ] *['\"](.*)['\"]\\)? *,/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment