futuremint (owner)

Fork Of

Revisions

gist: 98744 Download_button fork
public
Description:
Translates RSpec to Shoulda in your current Emacs buffer (tested in GNU Emacs only)
Public Clone URL: git://gist.github.com/98744.git
Embed All Files: show embed
really_hackish_spec_to_shoulda.el #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(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))))))