From 8523372f911a1852cc1f32b7d06e8f07c9ed6a0f Mon Sep 17 00:00:00 2001 From: crazypit Date: Fri, 24 Aug 2007 12:57:59 +0000 Subject: [PATCH] * rails-spec.el: base support for rspec. Function `rails-spec:run-all', `rails-spec:run-this-file', `rails-spec:run-last', `rails-spec:run-files'. Variables: `rails-spec:all-files', `rails-spec:last-files', `rails-spec:runner', `rails-spec:runner-options'. * rails-find.el, rails-ui.el: finds for rspec * rails-project.el: new functions: rails-project:in-root-with-cd, rails-project:compile-in-root * rails-lib.el: new macro in-directory M trunk/rails-lib.el M trunk/rails-project.el M trunk/rails-ui.el M trunk/rails-find.el M trunk/ChangeLog A trunk/rails-spec.el M trunk/rails.el git-svn-id: svn+ssh://rubyforge.org/var/svn/emacs-rails/trunk@213 cc5033d0-740f-0410-afc7-949910e492f2 --- ChangeLog | 11 +++++++++ rails-find.el | 7 ++++++ rails-lib.el | 9 +++++++ rails-project.el | 9 +++++++ rails-spec.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ rails-ui.el | 9 +++++++ rails.el | 1 + 7 files changed, 110 insertions(+) create mode 100644 rails-spec.el diff --git a/ChangeLog b/ChangeLog index 603259b..399cfe4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-08-18 Peter Rezikov + * rails-spec.el: base support for rspec. Function + `rails-spec:run-all', `rails-spec:run-this-file', `rails-spec:run-last', + `rails-spec:run-files'. Variables: `rails-spec:all-files', + `rails-spec:last-files', `rails-spec:runner', + `rails-spec:runner-options'. + * rails-find.el, rails-ui.el: finds for rspec + * rails-project.el: new functions: rails-project:in-root-with-cd, + rails-project:compile-in-root + * rails-lib.el: new macro in-directory + 2007-08-18 Dmitry Galinsky * rails-scripts.el (rails-script:run-interactive): setup a diff --git a/rails-find.el b/rails-find.el index f06ad62..237b8e9 100644 --- a/rails-find.el +++ b/rails-find.el @@ -51,4 +51,11 @@ (rails-find:gen "migrate" "db/migrate") (rails-find:gen "fixtures" "test/fixtures") +;; Rspec +(rails-find:gen "spec" "spec/") +(rails-find:gen "spec-controllers" "spec/controllers/") +(rails-find:gen "spec-models" "spec/models/") +(rails-find:gen "spec-helpers" "spec/helpers/") +(rails-find:gen "spec-fixtures" "spec/fixtures/") + (provide 'rails-find) \ No newline at end of file diff --git a/rails-lib.el b/rails-lib.el index 828dc78..69417f3 100644 --- a/rails-lib.el +++ b/rails-lib.el @@ -252,6 +252,15 @@ it." "Return the parent directory of a file named FILE-NAME." (replace-regexp-in-string "[^/]*$" "" file-name)) +(defmacro* in-directory ((directory) &rest body) + (let ((before-directory (gensym))) + `(let ((,before-directory default-directory) + (default-directory ,directory)) + (cd ,directory) + ,@body + (cd ,before-directory)))) + + ;; Buffers (defun buffer-string-by-name (buffer-name) diff --git a/rails-project.el b/rails-project.el index 1015b36..6d6e27b 100644 --- a/rails-project.el +++ b/rails-project.el @@ -65,6 +65,15 @@ BODY is executed." (let ((default-dir ,root)) ,@body)))) +(defmacro* rails-project:in-root-with-cd (&rest body) + (let ((root (gensym))) + `(rails-project:with-root (,root) + (in-directory (,root) ,@body)))) + +(defun rails-project:compile-in-root (command) + (rails-project:in-root-with-cd + (compile command))) + (defun rails-project:name () "Return the name of current Rails project." (replace-regexp-in-string "^.*/\\(.*\\)/$" "\\1" diff --git a/rails-spec.el b/rails-spec.el new file mode 100644 index 0000000..eec80e4 --- /dev/null +++ b/rails-spec.el @@ -0,0 +1,64 @@ +;;; rails-rake.el --- emacs-rails integraions with rake tasks. + +;; Copyright (C) 2006 Dmitry Galinsky + +;; Authors: Dmitry Galinsky , +;; Peter Rezikov +;; Keywords: ruby rails languages oop +;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails-spec.el $ +;; $Id: rails-spec.el 117 2007-03-25 23:37:37Z dimaexe $ + +;;; License + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License +;; as published by the Free Software Foundation; either version 2 +;; of the License, or (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +(defvar rails-spec:all-files "./spec" + "All spec files/directories in project") + +(defvar rails-spec:last-files rails-spec:all-files + "Last files that run with spec. In this variable memorized each spec coommand.") + +(defvar rails-spec:runner "./script/spec" + "Command, that run specs.") + +(defvar rails-spec:runner-options "" + "Options to spec command.") + +(defun rails-spec:run-files (files) + "Run spec for files" + (interactive "Mspec files: ") + (setf rails-spec:last-files files) + (let ((default-process-coding-system '(utf-8 . utf-8))) + (rails-project:compile-in-root + (concat rails-spec:runner " " + rails-spec:runner-options " " + files)))) + +(defun rails-spec:run-this-file () + "Run spec for current file" + (interactive) + (rails-spec:run-files (buffer-file-name (current-buffer)))) + +(defun rails-spec:run-all () + "Run spec for all files in project (rails-spec:all-files variable)" + (interactive) + (rails-spec:run-files rails-spec:all-files)) + +(defun rails-spec:run-last () + "Run last runned spec command" + (interactive) + (rails-spec:run-files rails-spec:last-files)) + +(provide 'rails-spec) diff --git a/rails-ui.el b/rails-ui.el index b9de370..d5298e3 100644 --- a/rails-ui.el +++ b/rails-ui.el @@ -262,12 +262,21 @@ ((rails-key "\C-c f p") 'rails-find:public) ((rails-key "\C-c f f") 'rails-find:fixtures) ((rails-key "\C-c f o") 'rails-find:config) + ;; Spec finds + ((rails-key "\C-c f r s") 'rails-find:spec) + ((rails-key "\C-c f r c") 'rails-find:spec-controllers) + ((rails-key "\C-c f r m") 'rails-find:spec-models) + ((rails-key "\C-c f r h") 'rails-find:spec-helpers) + ((rails-key "\C-c f r v") 'rails-find:spec-views) + ((rails-key "\C-c f r f") 'rails-find:spec-fixtures) ((rails-key "\C-c d m") 'rails-rake:migrate) ((rails-key "\C-c d v") 'rails-rake:migrate-to-version) ((rails-key "\C-c d p") 'rails-rake:migrate-to-prev-version) ((rails-key "\C-c d t") 'rails-rake:clone-development-db-to-test-db) + + ;; Tests ((rails-key "\C-c r") 'rails-rake:task) ((rails-key "\C-c t") 'rails-test:run) diff --git a/rails.el b/rails.el index 5348578..99e0791 100644 --- a/rails.el +++ b/rails.el @@ -68,6 +68,7 @@ (require 'rails-model-layout) (require 'rails-controller-layout) (require 'rails-features) +(require 'rails-spec) ;;;;;;;;;; Variable definition ;;;;;;;;;;