Browse files

rspec mode + snippets

  • Loading branch information...
0 parents commit 8f4c1f2ce01296f24e0c1b6ee4edc64c923612d6 @patmaddox committed Dec 17, 2008
48 rspec-mode.el
@@ -0,0 +1,48 @@
+;;;
+;;; rspec-mode.el
+;;;
+;;; Pat Maddox
+
+(define-derived-mode rspec-mode ruby-mode
+ "Toggle RSpec mode"
+ nil
+ " RSpec")
+(add-to-list 'auto-mode-alist '("_spec.rb$" . rspec-mode))
+
+(defun rails-root (&optional dir)
+ (or dir (setq dir default-directory))
+ (if (file-exists-p (concat dir "config/environment.rb"))
+ dir
+ (unless (equal dir "/")
+ (rails-root (expand-file-name (concat dir "../"))))))
+
+(defun spec-command ()
+ (if (rails-root)
+ (let ((script-spec (concat (rails-root) "script/spec"))
+ (plugin-spec (concat (rails-root) "vendor/plugins/rspec/bin/spec")))
+ (cond ((file-exists-p script-spec) script-spec)
+ ((file-exists-p plugin-spec) plugin-spec)
+ (t "spec")))
+ "spec"))
+
+(defun run-specs ()
+ "Run specs and display results in same buffer"
+ (interactive)
+ (do-run-spec))
+
+(defun run-focused-spec ()
+ "Run the example defined on the current line"
+ (interactive)
+ (do-run-spec (concat "--line=" (number-to-string (line-number-at-pos)))))
+
+(require 'linkify)
+(defun do-run-spec (&rest args)
+ (setq rspec-results (get-buffer-create "rspec-results"))
+ (save-excursion
+ (set-buffer rspec-results)
+ (erase-buffer)
+ (setq linkify-regexps '("^\\(/.*\\):\\([0-9]*\\):$")))
+ (setq proc (apply #'start-process "rspec" rspec-results (spec-command) (buffer-file-name) args))
+ (set-process-filter proc 'linkify-filter)
+ (display-buffer rspec-results))
+(provide 'rspec-mode)
3 snippets/text-mode/ruby-mode/rspec-mode/anr
@@ -0,0 +1,3 @@
+#name: and_return($value)
+# --
+and_return(${1:value})$0
3 snippets/text-mode/ruby-mode/rspec-mode/anra
@@ -0,0 +1,3 @@
+#name: and_raise($error)
+# --
+and_raise(${1:RuntimeError})$0
5 snippets/text-mode/ruby-mode/rspec-mode/bfe
@@ -0,0 +1,5 @@
+#name: before(:each) do ... end
+# --
+before(:each) do
+ $0
+end
5 snippets/text-mode/ruby-mode/rspec-mode/des
@@ -0,0 +1,5 @@
+#name: describe "an object" do ... end
+# --
+describe "${1:an object}" do
+ $0
+end
5 snippets/text-mode/ruby-mode/rspec-mode/dest
@@ -0,0 +1,5 @@
+#name: describe SomeClass do ... end
+# --
+describe ${1:SomeClass} do
+ $0
+end
5 snippets/text-mode/ruby-mode/rspec-mode/it
@@ -0,0 +1,5 @@
+#name: it "should do something" do ... end
+# --
+it "should ${1:do something}" do
+ $0
+end
3 snippets/text-mode/ruby-mode/rspec-mode/shr
@@ -0,0 +1,3 @@
+#name: $target.should_receive(:$message)
+# --
+${1:target}.should_receive(:${2:message})$0
3 snippets/text-mode/ruby-mode/rspec-mode/shrt
@@ -0,0 +1,3 @@
+#name: response.should render_template("$template")
+# --
+response.should render_template("${0:template}")
3 snippets/text-mode/ruby-mode/rspec-mode/stub
@@ -0,0 +1,3 @@
+#name: $target.stub!(:$message)
+# --
+${1:target}.stub!(:${2:message})$0

0 comments on commit 8f4c1f2

Please sign in to comment.