gist: 13345 Download_button fork
public
Public Clone URL: git://gist.github.com/13345.git
emacs-rails.switch-rspec.from-r232.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
Index: rails-speedbar-feature.el
===================================================================
--- rails-speedbar-feature.el  (リビジョン 232)
+++ rails-speedbar-feature.el  (作業コピー)
@@ -8,7 +8,13 @@
     ("Functional Tests" rails-core:functional-tests rails-core:functional-test-file)
     ("Unit Tests" rails-core:unit-tests rails-core:unit-test-file)
     ("Fixtures" rails-core:fixtures rails-core:fixture-file)
- ("Configuration" rails-core:configuration-files rails-core:configuration-file)))
+ ("Configuration" rails-core:configuration-files rails-core:configuration-file)
+ ("RSpec Controllers" rails-core:rspec-controllers rails-core:rspec-controller-file)
+ ("RSpec Fixtures" rails-core:rspec-fixtures rails-core:rspec-fixture-file)
+ ("RSpec Lib" rails-core:rspec-lib rails-core:rspec-lib-file)
+ ("RSpec Models" rails-core:rspec-models rails-core:rspec-model-file)
+ ("RSpec Views" rails-core:rspec-views rails-core:rspec-view-file)
+ ("Fixtures" rails-core:fixtures rails-core:fixture-file)))
 
 (defvar rails-speedbar:menu-items nil)
 (defvar rails-speedbar:key-map
Index: rails-rspec-model-minor-mode.el
===================================================================
--- rails-rspec-model-minor-mode.el  (リビジョン 0)
+++ rails-rspec-model-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,15 @@
+(define-minor-mode rails-rspec-model-minor-mode
+ "Minor mode for RubyOnRails models rspec."
+ :lighter " ModelRSpec"
+ :keymap (let ((map (rails-model-layout:keymap :rspec-model)))
+ (define-key map rails-minor-mode-test-current-method-key 'rails-rspec:run-current-method)
+ (define-key map [menu-bar rails-model-layout run] '("RSpec current method" . rails-rspec:run-current-method))
+ map)
+ (setq rails-primary-switch-func (lambda()
+ (interactive)
+ (if (rails-core:mailer-p (rails-core:current-model))
+ (rails-model-layout:switch-to-mailer)
+ (rails-model-layout:switch-to-model))))
+ (setq rails-secondary-switch-func 'rails-model-layout:menu))
+
+(provide 'rails-rspec-model-minor-mode)
\ No newline at end of file
Index: rails-rspec-lib-minor-mode.el
===================================================================
--- rails-rspec-lib-minor-mode.el  (リビジョン 0)
+++ rails-rspec-lib-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,11 @@
+(define-minor-mode rails-rspec-lib-minor-mode
+ "Minor mode for RubyOnRails lib rspec."
+ :lighter " LibRSpec"
+ :keymap (let ((map (rails-lib-layout:keymap :rspec-lib)))
+ (define-key map rails-minor-mode-test-current-method-key 'rails-rspec:run-current-method)
+ (define-key map [menu-bar rails-lib-layout run] '("RSPec current method" . rails-rspec:run-current-method))
+ map)
+ (setq rails-primary-switch-func 'rails-lib-layout:switch-to-lib)
+ (setq rails-secondary-switch-func 'rails-lib-layout:menu))
+
+(provide 'rails-rspec-lib-minor-mode)
\ No newline at end of file
Index: rails-core.el
===================================================================
--- rails-core.el  (リビジョン 232)
+++ rails-core.el  (作業コピー)
@@ -35,12 +35,17 @@
     "app/helpers"
     "test/unit"
     "test/functional"
- "test/fixtures")
+ "test/fixtures"
+ "spec/controllers"
+ "spec/fixtures"
+ "spec/lib"
+ "spec/models"
+ "lib")
   "Directories with Rails classes")
 
 (defun rails-core:class-by-file (filename)
   "Return the class associated with FILENAME.
- <rails-root>/(app/models|app/controllers|app/helpers|test/unit|test/functional)/foo/bar_baz
+ <rails-root>/(app/models|app/controllers|app/helpers|test/unit|test/functional|lib|spec/controllers|spec/lib|spec/models)/foo/bar_baz
                 --> Foo::BarBaz"
   (let* ((case-fold-search nil)
          (path (replace-regexp-in-string
@@ -313,6 +318,50 @@
       controller
     (concat controller "Controller")))
 
+(defun rails-core:rspec-controller-file (controller)
+ "Return the controller spec file name for the controller named
+CONTROLLER."
+ (when controller
+ (format "spec/controllers/%s_spec.rb"
+ (rails-core:file-by-class (rails-core:long-controller-name controller) t))))
+
+(defun rails-core:lib-file (lib-name)
+ "Return the model file from the lib name."
+ (when lib-name
+ (concat "lib/" (rails-core:file-by-class lib-name))))
+
+(defun rails-core:rspec-lib-file (lib)
+ "Return the lib spec file name for the lib named LIB."
+ (when lib
+ (format "spec/lib/%s_spec.rb" (rails-core:file-by-class lib t))))
+
+(defun rails-core:rspec-model-file (model)
+ "Return the model spec file name for the model named MODEL."
+ (when model
+ (format "spec/models/%s_spec.rb" (rails-core:file-by-class model t))))
+
+(defun rails-core:rspec-fixture-file (model)
+ "Return the rspec fixtures file name for the model named MODEL."
+ (when model
+ (format "spec/fixtures/%s.yml" (pluralize-string (rails-core:file-by-class model t)))))
+
+(defun rails-core:rspec-lib-exist-p (lib)
+ "Return the lib spec file name for the model named MODEL."
+ (let ((spec (rails-core:rspec-lib-file lib)))
+ (when spec
+ (file-exists-p (rails-core:file spec)))))
+
+(defun rails-core:rspec-model-exist-p (model)
+ "Return the model spec file name for the model named MODEL."
+ (let ((spec (rails-core:rspec-model-file model)))
+ (when spec
+ (file-exists-p (rails-core:file spec)))))
+
+(defun rails-core:rspec-fixture-exist-p (model)
+ (when model
+ (file-exists-p
+ (rails-core:file (rails-core:rspec-fixture-file model)))))
+
 ;;;;;;;;;; Functions that return collection of Rails objects ;;;;;;;;;;
 (defun rails-core:observer-p (name)
   (when name
@@ -483,6 +532,29 @@
   "Return the parent classes of controllers."
   (rails-core:extract-ancestors (rails-core:controllers)))
 
+(defun rails-core:rspec-controllers ()
+ "Return a list of Rails controller specs."
+ (mapcar
+ #'(lambda(it)
+ (remove-postfix (rails-core:class-by-file it)
+ "Spec"))
+ (find-recursive-files "\\.rb$" (rails-core:file "spec/controllers/"))))
+
+(defun rails-core:rspec-models ()
+ "Return a list of Rails model specs."
+ (mapcar
+ #'(lambda(it)
+ (remove-postfix (rails-core:class-by-file it)
+ "Spec"))
+ (find-recursive-files "\\.rb$" (rails-core:file "spec/models/"))))
+
+(defun rails-core:rspec-fixtures ()
+ "Return a list of Rails RSpec fixtures."
+ (mapcar
+ #'(lambda (l)
+ (replace-regexp-in-string "\\.[^.]+$" "" l))
+ (find-recursive-files "\\.yml$" (rails-core:file "spec/fixtures/"))))
+
 ;;;;;;;;;; Getting Controllers/Model/Action from current buffer ;;;;;;;;;;
 
 (defun rails-core:current-controller ()
@@ -494,7 +566,8 @@
         (:view (rails-core:class-by-file
                 (directory-file-name (directory-of-file (buffer-file-name)))))
         (:helper (remove-postfix file-class "Helper"))
- (:functional-test (remove-postfix file-class "ControllerTest"))))))
+ (:functional-test (remove-postfix file-class "ControllerTest"))
+ (:rspec-controller (remove-postfix file-class "Spec"))))))
 
 (defun rails-core:current-model ()
   "Return the current Rails model."
@@ -504,8 +577,18 @@
         (:migration (rails-core:model-by-migration-filename (buffer-name)))
         (:model file-class)
         (:unit-test (remove-postfix file-class "Test"))
- (:fixture (singularize-string file-class))))))
+ (:fixture (singularize-string file-class))
+ (:rspec-fixture (singularize-string file-class))
+ (:rspec-model (remove-postfix file-class "Spec"))))))
 
+(defun rails-core:current-lib ()
+ "Return the current lib."
+ (let* ((file-class (rails-core:class-by-file (buffer-file-name))))
+ (unless (rails-core:mailer-p file-class)
+ (case (rails-core:buffer-type)
+ (:lib file-class)
+ (:rspec-lib (remove-postfix file-class "Spec"))))))
+
 (defun rails-core:current-mailer ()
   "Return the current Rails Mailer, else return nil."
   (let* ((file-class (rails-core:class-by-file (buffer-file-name)))
@@ -671,4 +754,8 @@
   "Return non nil if the current buffer is rhtml file."
   (string-match "\\.rhtml$" (buffer-file-name)))
 
+(defun rails-core:spec-exist-p ()
+ "Return non nil if spec directory is exist."
+ (file-exists-p (rails-core:file "spec")))
+
 (provide 'rails-core)
Index: rails-controller-layout.el
===================================================================
--- rails-controller-layout.el  (リビジョン 232)
+++ rails-controller-layout.el  (作業コピー)
@@ -63,7 +63,8 @@
       (:controller
        (if action-name
            (rails-controller-layout:switch-to-view controller-name action-name)
- (rails-controller-layout:switch-to :functional-test))))))
+ (if (rails-core:spec-exist-p) (rails-controller-layout:switch-to :rspec-controller)
+ (rails-controller-layout:switch-to :functional-test)))))))
 
 (defun rails-controller-layout:create-view-for-action (controller-name action-name)
   (let ((type
@@ -133,6 +134,9 @@
                                        rails-controller-layout:switch-to-functional-test
                                        :enable (and (not (rails-core:current-mailer))
                                                     (not (eq (rails-core:buffer-type) :functional-test)))))
+ ([goto-rspec-controller] '(menu-item "Go to RSpec"
+ rails-controller-layout:switch-to-rspec-controller
+ :enable (not (eq (rails-core:buffer-type) :rspec-controller))))
         ([goto-controller] '(menu-item "Go to Controller"
                                        rails-controller-layout:switch-to-controller
                                        :enable (and (not (rails-core:current-mailer))
@@ -147,6 +151,7 @@
         ((rails-key "f") 'rails-controller-layout:switch-to-functional-test)
         ((rails-key "c") 'rails-controller-layout:switch-to-controller)
         ((rails-key "u") 'rails-controller-layout:switch-to-unit-test)
+ ((rails-key "r") 'rails-controller-layout:switch-to-rspec-controller)
         ([menu-bar rails-controller-layout] (cons name menu))))
     map))
 
@@ -158,6 +163,7 @@
          (item (case type
                  (:helper (rails-core:helper-file controller))
                  (:functional-test (rails-core:functional-test-file controller))
+ (:rspec-controller (rails-core:rspec-controller-file controller))
                  (:controller (rails-core:controller-file controller))
                  (:model (rails-core:model-file model))
                  (:unit-test (rails-core:unit-test-file mailer))
@@ -173,6 +179,7 @@
 
 (defun rails-controller-layout:switch-to-helper () (interactive) (rails-controller-layout:switch-to :helper))
 (defun rails-controller-layout:switch-to-functional-test () (interactive) (rails-controller-layout:switch-to :functional-test))
+(defun rails-controller-layout:switch-to-rspec-controller () (interactive) (rails-controller-layout:switch-to :rspec-controller))
 (defun rails-controller-layout:switch-to-controller () (interactive) (rails-controller-layout:switch-to :controller))
 (defun rails-controller-layout:switch-to-model () (interactive) (rails-controller-layout:switch-to :model))
 (defun rails-controller-layout:switch-to-migration () (interactive) (rails-controller-layout:switch-to :migration))
@@ -197,6 +204,8 @@
         (add-to-list 'item (cons "Helper" :helper)))
       (unless (eq type :functional-test)
         (add-to-list 'item (cons "Functional Test" :functional-test)))
+ (unless (eq type :rspec-controller)
+ (add-to-list 'item (cons "RSpec" :rspec-controller)))
       (unless (eq type :controller)
         (add-to-list 'item (cons "Controller" :controller))))
     (when mailer
Index: rails-navigation.el
===================================================================
--- rails-navigation.el  (リビジョン 232)
+++ rails-navigation.el  (作業コピー)
@@ -136,6 +136,46 @@
    (lambda (plugin)
      (concat "vendor/plugins/" plugin "/init.rb"))))
 
+(defun rails-nav:goto-rspec-controllers ()
+ "Go to controller specs."
+ (interactive)
+ (rails-nav:goto-file-with-menu-from-list
+ (rails-core:rspec-controllers)
+ "Go to controller spec."
+ 'rails-core:rspec-controller-file))
+
+(defun rails-nav:goto-rspec-lib ()
+ "Go to lib specs."
+ (interactive)
+ (rails-nav:goto-file-with-menu-from-list
+ (rails-core:rspec-lib)
+ "Go to lib spec."
+ 'rails-core:rspec-lib-file))
+
+(defun rails-nav:goto-rspec-models ()
+ "Go to model specs."
+ (interactive)
+ (rails-nav:goto-file-with-menu-from-list
+ (rails-core:rspec-models)
+ "Go to model spec."
+ 'rails-core:rspec-model-file))
+
+(defun rails-nav:goto-rspec-views ()
+ "Go to view specs."
+ (interactive)
+ (rails-nav:goto-file-with-menu-from-list
+ (rails-core:rspec-views)
+ "Go to view spec."
+ 'rails-core:rspec-view-file))
+
+(defun rails-nav:goto-rspec-fixtures ()
+ "Go to rspec fuxtures."
+ (interactive)
+ (rails-nav:goto-file-with-menu-from-list
+ (rails-core:rspec-fixtures)
+ "Go to rspec fixtures."
+ 'rails-core:rspec-fixture-file))
+
 (defun rails-nav:create-new-layout (&optional name)
   "Create a new layout."
   (let ((name (or name (read-string "Layout name? "))))
Index: rails-model-minor-mode.el
===================================================================
--- rails-model-minor-mode.el  (リビジョン 232)
+++ rails-model-minor-mode.el  (作業コピー)
@@ -30,7 +30,8 @@
   "Minor mode for RubyOnRails models."
   :lighter " Model"
   :keymap (rails-model-layout:keymap :model)
- (setq rails-primary-switch-func 'rails-model-layout:switch-to-unit-test)
+ (if (rails-core:spec-exist-p) (setq rails-primary-switch-func 'rails-model-layout:switch-to-rspec-model)
+ (setq rails-primary-switch-func 'rails-model-layout:switch-to-unit-test))
   (setq rails-secondary-switch-func 'rails-model-layout:menu))
 
 (provide 'rails-model-minor-mode)
\ No newline at end of file
Index: rails-rspec-fixture-minor-mode.el
===================================================================
--- rails-rspec-fixture-minor-mode.el  (リビジョン 0)
+++ rails-rspec-fixture-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,8 @@
+(define-minor-mode rails-rspec-fixture-minor-mode
+ "Minor mode for RubyOnRails rspec fixtures."
+ :lighter " RSpecFixture"
+ :keymap (rails-model-layout:keymap :rspec-fixture)
+ (setq rails-primary-switch-func 'rails-model-layout:switch-to-rspec-model)
+ (setq rails-secondary-switch-func 'rails-model-layout:menu))
+
+(provide 'rails-rspec-fixture-minor-mode)
\ No newline at end of file
Index: rails-lib-minor-mode.el
===================================================================
--- rails-lib-minor-mode.el  (リビジョン 0)
+++ rails-lib-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,8 @@
+(define-minor-mode rails-lib-minor-mode
+ "Minor mode for RubyOnRails libs."
+ :lighter " Lib"
+ :keymap (rails-model-layout:keymap :lib)
+ (setq rails-primary-switch-func 'rails-lib-layout:switch-to-rspec-lib)
+ (setq rails-secondary-switch-func 'rails-lib-layout:menu))
+
+(provide 'rails-lib-minor-mode)
\ No newline at end of file
Index: rails-model-layout.el
===================================================================
--- rails-model-layout.el  (リビジョン 232)
+++ rails-model-layout.el  (作業コピー)
@@ -41,6 +41,11 @@
                                        :enable (and (not (eq (rails-core:buffer-type) :unit-test))
                                                     (rails-core:unit-test-exist-p (or (rails-core:current-model)
                                                                                       (rails-core:current-mailer))))))
+ ([goto-rspec] '(menu-item "Go to RSpec"
+ rails-model-layout:switch-to-rspec-model
+ :enable (and (not (eq (rails-core:buffer-type) :rspec-model))
+ (rails-core:rspec-model-exist-p (or (rails-core:current-model)
+ (rails-core:current-mailer))))))
         ([goto-migration] '(menu-item "Go to Migration"
                                        rails-model-layout:switch-to-migration
                                        :enable (and (not (eq (rails-core:buffer-type) :migration))
@@ -52,15 +57,21 @@
                                        rails-model-layout:switch-to-fixture
                                        :enable (and (not (eq (rails-core:buffer-type) :fixture))
                                                     (rails-core:fixture-exist-p (rails-core:current-model)))))
+ ([goto-rspec-fixture] '(menu-item "Go to RSpec Fixture"
+ rails-model-layout:switch-to-rspec-fixture
+ :enable (and (not (eq (rails-core:buffer-type) :rspec-fixture))
+ (rails-core:rspec-fixture-exist-p (rails-core:current-model)))))
         ([goto-mailer] '(menu-item "Go to Mailer"
                                        rails-model-layout:switch-to-mailer
                                        :enable (rails-core:mailer-exist-p (rails-core:current-mailer)))))
       (define-keys map
         ((rails-key "m") 'rails-model-layout:switch-to-model)
         ((rails-key "u") 'rails-model-layout:switch-to-unit-test)
+ ((rails-key "r") 'rails-model-layout:switch-to-rspec-model)
         ((rails-key "g") 'rails-model-layout:switch-to-migration)
         ((rails-key "c") 'rails-model-layout:switch-to-controller)
         ((rails-key "x") 'rails-model-layout:switch-to-fixture)
+ ((rails-key "z") 'rails-model-layout:switch-to-rspec-fixture)
         ((rails-key "n") 'rails-model-layout:switch-to-mailer)
         ([menu-bar rails-model-layout] (cons name menu))))
     map))
@@ -75,7 +86,9 @@
                  (:mailer (rails-core:mailer-file mailer))
                  (:controller (rails-core:controller-file-by-model model))
                  (:fixture (rails-core:fixture-file model))
+ (:rspec-fixture (rails-core:rspec-fixture-file model))
                  (:unit-test (rails-core:unit-test-file item))
+ (:rspec-model (rails-core:rspec-model-file item))
                  (:model (rails-core:model-file model))
                  (:migration (rails-core:migration-file-by-model model)))))
     (if item
@@ -90,7 +103,9 @@
 (defun rails-model-layout:switch-to-mailer () (interactive) (rails-model-layout:switch-to :mailer))
 (defun rails-model-layout:switch-to-controller () (interactive) (rails-model-layout:switch-to :controller))
 (defun rails-model-layout:switch-to-fixture () (interactive) (rails-model-layout:switch-to :fixture))
+(defun rails-model-layout:switch-to-rspec-fixture () (interactive) (rails-model-layout:switch-to :rspec-fixture))
 (defun rails-model-layout:switch-to-unit-test () (interactive) (rails-model-layout:switch-to :unit-test))
+(defun rails-model-layout:switch-to-rspec-model () (interactive) (rails-model-layout:switch-to :rspec-model))
 (defun rails-model-layout:switch-to-model () (interactive) (rails-model-layout:switch-to :model))
 (defun rails-model-layout:switch-to-migration () (interactive) (rails-model-layout:switch-to :migration))
 
@@ -108,10 +123,14 @@
         (add-to-list 'item (cons "Migration" :migration)))
       (unless (eq type :fixture)
         (add-to-list 'item (cons "Fixture" :fixture)))
+ (unless (eq type :rspec-fixture)
+ (add-to-list 'item (cons "RSpec Fixture" :rspec-fixture)))
       (when (rails-core:controller-exist-p controller)
         (add-to-list 'item (cons "Controller" :controller)))
       (unless (eq type :unit-test)
         (add-to-list 'item (cons "Unit Test" :unit-test)))
+ (unless (eq type :rspec-model)
+ (add-to-list 'item (cons "RSpec" :rspec-model)))
       (unless (eq type :model)
         (add-to-list 'item (cons "Model" :model))))
     (when mailer
Index: rails-ui.el
===================================================================
--- rails-ui.el  (リビジョン 232)
+++ rails-ui.el  (作業コピー)
@@ -80,7 +80,11 @@
       ([goto-unit-tests] '("Go to Unit Tests" . rails-nav:goto-unit-tests))
       ([goto-func-tests] '("Go to Functional Tests" . rails-nav:goto-functional-tests))
       ([goto-models] '("Go to Models" . rails-nav:goto-models))
- ([goto-controllers] '("Go to Controllers" . rails-nav:goto-controllers)))
+ ([goto-controllers] '("Go to Controllers" . rails-nav:goto-controllers))
+ ([goto-rspec-controllers] '("Go to RSpec Controllers" . rails-nav:goto-rspec-controllers))
+ ([goto-rspec-lib] '("Go to RSpec Lib" . rails-nav:goto-rspec-lib))
+ ([goto-rspec-models] '("Go to RSpec Models" . rails-nav:goto-rspec-models))
+ ([goto-rspec-fixtures] '("Go to RSpec Fixtures" . rails-nav:goto-rspec-fixtures)))
     map))
 
 (defconst rails-minor-mode-tests-menu-bar-map
@@ -229,6 +233,10 @@
   ((rails-key "\C-c g x") 'rails-nav:goto-fixtures)
   ((rails-key "\C-c g f") 'rails-nav:goto-functional-tests)
   ((rails-key "\C-c g u") 'rails-nav:goto-unit-tests)
+ ((rails-key "\C-c g r c") 'rails-nav:goto-rspec-controllers)
+ ((rails-key "\C-c g r f") 'rails-nav:goto-rspec-fixtures)
+ ((rails-key "\C-c g r l") 'rails-nav:goto-rspec-lib)
+ ((rails-key "\C-c g r m") 'rails-nav:goto-rspec-models)
 
   ;; Switch
   ((kbd "<M-S-up>") 'rails-lib:run-primary-switch)
@@ -278,18 +286,23 @@
   ((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)
   ((rails-key "\C-c .") 'rails-test:run-current)
- ((rails-key "\C-c y i") 'rails-test:run-integration)
- ((rails-key "\C-c y u") 'rails-test:run-units)
- ((rails-key "\C-c y f") 'rails-test:run-functionals)
+ ((rails-key "\C-c y i") 'rails-test:run-integration)
+ ((rails-key "\C-c y u") 'rails-test:run-units)
+ ((rails-key "\C-c y f") 'rails-test:run-functionals)
   ((rails-key "\C-c #") 'rails-test:run-recent)
- ((rails-key "\C-c y a") 'rails-test:run-all)
+ ((rails-key "\C-c y a") 'rails-test:run-all)
 
+ ;; RSpec
+ ((rails-key "\C-c z f") 'rails-spec:run-files)
+ ((rails-key "\C-c z .") 'rails-spec:run-this-file)
+ ((rails-key "\C-c z a") 'rails-spec:run-all)
+ ((rails-key "\C-c z l") 'rails-spec:run-last)
+ ((rails-key "\C-c z s") 'rails-spec:run-this-spec)
+
   ;; Log files
   ((rails-key "\C-c l") 'rails-log:open)
   ((rails-key "\C-c o t") 'rails-log:open-test)
Index: rails-find.el
===================================================================
--- rails-find.el  (リビジョン 232)
+++ rails-find.el  (作業コピー)
@@ -55,6 +55,7 @@
 (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/views/")
 (rails-find:gen "spec-helpers" "spec/helpers/")
 (rails-find:gen "spec-fixtures" "spec/fixtures/")
 
Index: rails-rspec-minor-mode.el
===================================================================
--- rails-rspec-minor-mode.el  (リビジョン 0)
+++ rails-rspec-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,15 @@
+(define-minor-mode rails-rspec-minor-mode
+ "Minor mode for RubyOnRails RSpec."
+ :lighter " RSpec"
+ :keymap (let ((map (rails-model-layout:keymap :rspec)))
+ ; (define-key map rails-minor-mode-test-current-method-key 'rails-test:run-current-method)
+ ; (define-key map [menu-bar rails-model-layout run] '("Test current method" . rails-test:run-current-method))
+ map)
+ (setq rails-primary-switch-func (lambda()
+ (interactive)
+ (if (rails-core:mailer-p (rails-core:current-model))
+ (rails-model-layout:switch-to-mailer)
+ (rails-model-layout:switch-to-model))))
+ (setq rails-secondary-switch-func 'rails-model-layout:menu))
+
+(provide 'rails-rspec-minor-mode)
\ No newline at end of file
Index: rails-lib-layout.el
===================================================================
--- rails-lib-layout.el  (リビジョン 0)
+++ rails-lib-layout.el  (リビジョン 0)
@@ -0,0 +1,61 @@
+(defun rails-lib-layout:keymap (type)
+ (let* ((name (capitalize (substring (symbol-name type) 1)))
+ (map (make-sparse-keymap))
+ (menu (make-sparse-keymap)))
+ (when type
+ (define-keys menu
+ ([goto-lib] '(menu-item "Go to Lib"
+ rails-lib-layout:switch-to-lib
+ :enable (and (not (eq (rails-core:buffer-type) :lib))
+ (rails-core:lib-exist-p (rails-core:current-lib)))))
+ ([goto-rspec] '(menu-item "Go to RSpec"
+ rails-lib-layout:switch-to-rspec-lib
+ :enable (and (not (eq (rails-core:buffer-type) :rspec-lib))
+ (rails-core:rspec-lib-exist-p (rails-core:current-lib))))))
+ (define-keys map
+ ((rails-key "l") 'rails-lib-layout:switch-to-lib)
+ ((rails-key "r") 'rails-lib-layout:switch-to-unit-test)
+ ([menu-bar rails-lib-layout] (cons name menu))))
+ map))
+
+(defun rails-lib-layout:switch-to (type)
+ (let* ((name (capitalize (substring (symbol-name type) 1)))
+ (lib (rails-core:current-lib))
+ (item (if lib lib))
+ (item (case type
+ (:rspec-lib (rails-core:rspec-lib-file item))
+ (:lib (rails-core:lib-file lib)))))
+ (if item
+ (let ((file (rails-core:file item)))
+ (if (file-exists-p file)
+ (progn
+ (find-file file)
+ (message (format "%s: %s" (substring (symbol-name type) 1) item)))
+ (message "File %s not exists" file)))
+ (message "%s not found" name))))
+
+(defun rails-lib-layout:switch-to-rspec-lib () (interactive) (rails-lib-layout:switch-to :rspec-lib))
+(defun rails-lib-layout:switch-to-lib () (interactive) (rails-lib-layout:switch-to :lib))
+
+(defun rails-lib-layout:menu ()
+ (interactive)
+ (let* ((item (list))
+ (type (rails-core:buffer-type))
+ (title (capitalize (substring (symbol-name type) 1)))
+ (lib (rails-core:current-lib)))
+ (when lib
+ (unless (eq type :rspec-lib)
+ (add-to-list 'item (cons "RSpec" :rspec-lib)))
+ (unless (eq type :lib)
+ (add-to-list 'item (cons "Lib" :lib))))
+ (when item
+ (setq item
+ (rails-core:menu
+ (list (concat title " " lib)
+ (cons "Please select.."
+ item))))
+ (typecase item
+ (symbol (rails-lib-layout:switch-to item))
+ (string (rails-core:find-file-if-exist item))))))
+
+(provide 'rails-lib-layout)
\ No newline at end of file
Index: rails-rspec-controller-minor-mode.el
===================================================================
--- rails-rspec-controller-minor-mode.el  (リビジョン 0)
+++ rails-rspec-controller-minor-mode.el  (リビジョン 0)
@@ -0,0 +1,11 @@
+(define-minor-mode rails-rspec-controller-minor-mode
+ "Minor mode for RubyOnRails controller rspec."
+ :lighter " ControllerRSpec"
+ :keymap (let ((map (rails-controller-layout:keymap :rspec-controllers)))
+ (define-key map rails-minor-mode-test-current-method-key 'rails-rspec:run-current-method)
+ (define-key map [menu-bar rails-controller-layout run] '("RSPec current method" . rails-rspec:run-current-method))
+ map)
+ (setq rails-primary-switch-func 'rails-controller-layout:switch-to-controller)
+ (setq rails-secondary-switch-func 'rails-controller-layout:menu))
+
+(provide 'rails-rspec-controller-minor-mode)
\ No newline at end of file
Index: rails.el
===================================================================
--- rails.el  (リビジョン 232)
+++ rails.el  (作業コピー)
@@ -67,6 +67,7 @@
 (require 'rails-model-layout)
 (require 'rails-controller-layout)
 (require 'rails-features)
+(require 'rails-lib-layout)
 (require 'rails-spec)
 
 
@@ -175,6 +176,11 @@
     (:unit-test "test/unit/")
     (:functional-test "test/functional/")
     (:fixture "test/fixtures/")
+ (:lib "lib")
+ (:rspec-controller "spec/controllers")
+ (:rspec-fixture "spec/fixtures")
+ (:rspec-lib "spec/lib")
+ (:rspec-model "spec/models")
     (:migration "db/migrate"))
   "Rails file types -- rails directories map")
 
@@ -411,7 +417,7 @@
             (modify-syntax-entry ?! "w" (syntax-table))
             (modify-syntax-entry ?: "w" (syntax-table))
             (modify-syntax-entry ?_ "w" (syntax-table))
- (local-set-key (kbd "C-.") 'complete-tag)
+ ;(local-set-key (kbd "C-.") 'complete-tag)
             (local-set-key (if rails-use-another-define-key
                                (kbd "TAB") (kbd "<tab>"))
                            'indent-and-complete)
 

Owner

koshigoe

Revisions