Skip to content

Commit

Permalink
Add snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
victorteokw committed Dec 3, 2014
1 parent 31644cb commit cd4800c
Show file tree
Hide file tree
Showing 39 changed files with 229 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ To enable minitest mode on ruby files:
(add-hook 'ruby-mode-hook 'minitest-mode)
```

## Snippets

To add snippets to yasnippet:
```lisp
(eval-after-load 'minitest-mode
'(minitest-install-snippets))
```

## License

The MIT License (MIT)
Expand Down
15 changes: 14 additions & 1 deletion minitest.el
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ The current directory is assumed to be the project's root otherwise."
:keymap minitest-mode-map
:group 'minitest)

(provide 'minitest)
(defvar minitest-snippets-dir
(let ((current-file-name (or load-file-name (buffer-file-name))))
(expand-file-name "snippets" (file-name-directory current-file-name)))
"The directory containing minitest snippets.")

(defun minitest-install-snippets ()
"Add `minitest-snippets-dir' to `yas-snippet-dirs' and load\
snippets from it."
(let ((yasnippet-available (require 'yasnippet nil t)))
(if yasnippet-available
(progn
(add-to-list 'yas-snippet-dirs minitest-snippets-dir t)
(yas-load-directory minitest-snippets-dir)))))

(provide 'minitest)
;;; minitest.el ends here
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert
# key: assert
# --
assert(${1:test}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_empty
# key: assert_empty
# --
assert_empty(${1:obj}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_equal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_equal
# key: assert_equal
# --
assert_equal(${1:exp}, ${2:act}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_in_delta
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_in_delta
# key: assert_in_delta
# --
assert_in_delta(${1:exp}, ${2:act}, ${3:delta = 0.001}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_in_epsilon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_in_epsilon
# key: assert_in_epsilon
# --
assert_in_epsilon(${1:a}, ${2:b}, ${3:epsilon = 0.001}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_includes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_includes
# key: assert_includes
# --
assert_includes(${1:collection}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_instance_of
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_instance_of
# key: assert_instance_of
# --
assert_instance_of(${1:cls}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_kind_of
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_kind_of
# key: assert_kind_of
# --
assert_kind_of(${1:cls}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_match
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_match
# key: assert_match
# --
assert_match(${1:matcher}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_nil
# key: assert_nil
# --
assert_nil(${1:obj}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_operator
# key: assert_operator
# --
assert_operator(${1:o1}, ${2:op}, ${3:o2 = UNDEFINED}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_output
# key: assert_output
# --
assert_output(${1:stdout = nil}, ${2:stderr = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_predicate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_predicate
# key: assert_predicate
# --
assert_predicate(${1:o1}, ${2:op}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_raises
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_raises
# key: assert_raises
# --
assert_raises(${1:*exp})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_respond_to
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_respond_to
# key: assert_respond_to
# --
assert_respond_to(${1:obj}, ${2:meth}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_same
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_same
# key: assert_same
# --
assert_same(${1:exp}, ${2:act}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_send
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_send
# key: assert_send
# --
assert_send(${1:send_ary}, ${2:m = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_silent
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_silent
# key: assert_silent
# --
assert_silent()$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/assert_throws
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: assert_throws
# key: assert_throws
# --
assert_throws(${1:sym}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/flunk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: flunk
# key: flunk
# --
flunk(${1:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: pass
# key: pass
# --
pass(${1:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute
# key: refute
# --
refute(${1:test}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_empty
# key: refute_empty
# --
refute_empty(${1:obj}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_equal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_equal
# key: refute_equal
# --
refute_equal(${1:exp}, ${2:act}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_in_delta
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_in_delta
# key: refute_in_delta
# --
refute_in_delta(${1:exp}, ${2:act}, ${3:delta = 0.001}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_in_epsilon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_in_epsilon
# key: refute_in_epsilon
# --
refute_in_epsilon(${1:a}, ${2:b}, ${3:epsilon = 0.001}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_includes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_includes
# key: refute_includes
# --
refute_includes(${1:collection}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_instance_of
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_instance_of
# key: refute_instance_of
# --
refute_instance_of(${1:cls}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_kind_of
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_kind_of
# key: refute_kind_of
# --
refute_kind_of(${1:cls}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_match
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_match
# key: refute_match
# --
refute_match(${1:matcher}, ${2:obj}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_nil
# key: refute_nil
# --
refute_nil(${1:obj}, ${2:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_operator
# key: refute_operator
# --
refute_operator(${1:o1}, ${2:op}, ${3:o2 = UNDEFINED}, ${4:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_predicate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_predicate
# key: refute_predicate
# --
refute_predicate(${1:o1}, ${2:op}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_respond_to
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_respond_to
# key: refute_respond_to
# --
refute_respond_to(${1:obj}, ${2:meth}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/refute_same
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: refute_same
# key: refute_same
# --
refute_same(${1:exp}, ${2:act}, ${3:msg = nil})$0
5 changes: 5 additions & 0 deletions snippets/minitest-mode/skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- mode: snippet; require-final-newline: nil -*-
# name: skip
# key: skip
# --
skip(${1:msg = nil}, ${2:bt = caller})$0
27 changes: 27 additions & 0 deletions tools/snippet_extractor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
documentation = `ri -a MiniTest::Assertions`
regex = /(?:assert|refute|flunk|pass|skip)\w*\(.*\)/
line_1 = "# -*- mode: snippet; require-final-newline: nil -*-"
line_2 = "# name: %s"
line_3 = "# key: %s"
line_4 = "# --"
dir = ARGV.first
exit if documentation.empty?
assertions = documentation.scan(regex)
Dir.mkdir(dir) unless Dir.exist?(dir)
assertions.each do |assertion|
# puts "Snippet for " << assertion
file_name = assertion[/.+?(?=\()/]
# puts "File name: " << file_name
snippet = assertion.gsub(/(?<=\(|, ).+?(?=\)\s*|,\s*)/).with_index do |m, i|
"${#{1+i}:#{m}}"
end
snippet = snippet << "$0"
# puts snippet
File.open(dir + ("/#{file_name}"),"w") do |file|
file.puts(line_1)
file.puts(sprintf(line_2, file_name))
file.puts(sprintf(line_3, file_name))
file.puts(line_4)
file.puts(snippet)
end
end

0 comments on commit cd4800c

Please sign in to comment.