I’m not the world’s biggest fan of unit testing, but this plugin for Vim looks great. I’ve not used any of the other Vim unit testing plugins so I can’t compare it to them, but I also can’t see what is not to like about it, especially the ability to run Python and Ruby code. It’s early doors yet, but I’m going to use it for Simplenote.vim:
Given:
A test note
Execute (Creating a new note):
:Simplenote -n
Execute python:
import os, sys
sys.path.append("/path/to/simplenote.py")
from simplenote import Simplenote
import vim
sn = Simplenote("username", "password")
snkey = vim.current.buffer.name.split("/")[-1]
note = sn.get_note(snkey)
vim.current.buffer.append(note[0]["content"])
Expect:
A test note
A test note
It works by manipulating and inspecting buffers. The Given
block fills a Vim buffer with text. The first Execute
block then runs pure Vimscript (which is obviously handy when testing Vim scripts) to manipulate the text in the buffer; although all that is being done here is creating a new note in Simplenote from the buffer. The second Execute
block runs Python instead of Vimscript, again the intention is to ultimately manipulate the buffer although here the ability to run Python proves more handy for verifying the creation of the note via simplenote.py
. Finally the Expect
block is what the buffer should look like after all the Execute
blocks have run and this is the crux of the test passing or failing.
In the plain Vimscript Execute
blocks Vader provides assertions that can be used instead of the Expect
blocks. I don’t think there is any way to use assertions in the Python block so here we have to use it to modify the buffer, appending the content of the note created - so what we expect to see is two lines of text of “A test note”. However, since the Python block will throw a wobbly anyway if the note doesn’t exists, I probably don’t need the Expect
block - although I suppose it is nice to verify the content of the note if it was successfully created.