Forked from jnunemaker/really_hackish_spec_to_shoulda.rb
Created
April 20, 2009 20:50
-
-
Save futuremint/98744 to your computer and use it in GitHub Desktop.
Translates RSpec to Shoulda in your current Emacs buffer (tested in GNU Emacs only)
This file contains hidden or 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
(defun rspec-to-shoulda () | |
"Translates RSpec code to Shoulda | |
NOTE: You still have to wrap the results in a Test::Unit class" | |
(interactive) | |
(dolist (pair '(("\\(require\s.*/\\)\\([a-z_]+\\)'$" "\\1test_helper'") ;; require | |
("describe\s" "context ") ;; RSpec -> Shoulda syntax | |
("it\s" "should ") | |
("\s\"should\s" " \"") | |
("before\s" "setup ") | |
("before(:each)\s" "setup ") | |
("\\(^\s+\\)\\([@a-zA-Z1-9\\._=\\?]+\\)\\.should\s==\s\\(.*\\)\s$" "\\1assert_equals(\\3, \\2)") ;; == matcher | |
("\\(^\s+\\)\\([@a-zA-Z1-9\\._=\\?]+\\)\\.should\sbe_?(?\\([a-zA-Z1-9_]+\\))?\s$" "\\1assert \\2.\\3?") ;; be_p matcher | |
("\\.should_receive" ".expects") ;; Flexmock -> Mocha | |
("\\.should_not_receive(\\(:[a-zA-Z1-9_=\\?]+\\))" ".expects(\\1).never") | |
("\\.stub!" ".stubs") | |
("\\.and_return" ".returns"))) | |
(save-excursion | |
(while (re-search-forward (car pair) nil t) | |
(replace-match (cadr pair)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment