sponsor Vim development Vim logo Vim Book Ad

spec.vim : Behaviour-driven design/testing for VIM script

 script karma  Rating 0/0, Downloaded by 1609  Comments, bugs, improvements  Vim wiki

created by
Tom Link
 
script type
utility
 
description
This plugin provides a small set of commands to facilitate
behaviour-driven design of vim plugins. It basically consists of two
parts:

    spec   ... BDD-related commands
    should ... Convenience functions for testing

According to BDD theory, you are supposed to write a specification first
and then make the code fulfill that specification. If you don't believe
in BDD, you could also think of spec.vim as a more convenient approach
to unit testing.

An example specification could look like this:

    SpecBegin 'title': 'Foo', 'sfile': 'autoload/foo.vim'

    It should add numbers.
    Should be equal foo#Add(1, 2), 3
    
    It should not add values of incompatible types.
    Should throw something 'foo#Add("1", 2)'

Specification scripts basically are normal vim scripts but must be run
by the |:Spec| command.

    :Spec[!] [PATH]
        Run one or more specification files.
        PATH can be either a file or a directory.

Each specification file should contain a :SpecBegin command that defines
the title, and optionally the script context, before/after commands, the
contents of a scratch buffer, option sets etc.

    :SpecBegin [ARGUMENTS AS INNER DICTIONNARY]
        Establish the environment for the current specification.
        Known keys for ARGUMENTS:
        
          title   ... The test's title.
          file    ... The script context.
          before  ... Code to be run before each test
          after   ... Code to be run after each test
          scratch ... Run spec in scratch buffer
          cleanup ... A list of function names that will be removed
          options ... Run the spec against different option sets

Examples:
http://github.com/tomtom/vimtlib/tree/master/spec/
 
install details
Edit the vba file and type: >

    :so %

See :help vimball for details. If you have difficulties or use vim 7.0,
please make sure, you have the current version of vimball
(vimscript #1502) installed or update your runtime.

Optional: Some "should"-functions require tlib (vimscript #1863) to be installed.

Also available via git
http://github.com/tomtom/spec_vim
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
spec.vba 0.2 2010-03-13 7.0 Tom Link - Display a message after having run all specs
- Raise an error when :SpecBegin is not called in a spec context (i.e. via the :Spec command)
spec.vba.gz 0.1 2009-03-11 7.0 Tom Link Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github