Skip to content

VimLondon/learn-vimscript-the-tdd-way

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn Vimscript the TDD way!

Setup

The test runner for this Vimscript Dojo depends on ruby tooling. You'll need to have each of the following installed on your system:

With those dependencies satisfied, run these steps to set up this Vimscript Dojo:

  • check out this repository: git clone git@github.com:VimLondon/learn-vimscript-the-tdd-way.git
  • cd learn-vimscript-the-tdd-way
  • install dependencies: bundle install
  • run the tests: bundle exec rake

You should have a passing test suite.

Also, it's advised that you install the vspec plugin for Vim, which adds indentation support for vspec files, and syntax highlighting for keywords describe, it, before, after, end.

Working through the exercises

The exercises are listed in the t directory. Open them up in Vim:

vim t/*

hint: that populates the argument list, so you can advance/reverse through the lessons by running :next/:prev.

You should start off in a file called t/001_about_true_and_false.vim. The tests should all pass at first, because the solutions are filled in. To conceal the answers, run this command:

:source conceal_solutions.vim

That script performs two changes to each example. It:

  • removes the solutions, and
  • marks each test as TODO

For example, this test:

it 'number 1 is treated as true'
  Expect ___('truthy') ==# TruthValue(1)
end

is converted to this:

it 'number 1 is treated as true'
  TODO
  Expect ___ ==# TruthValue(1)
end

The TODO statement prevents the test from running. Delete that line, then run the test suite and you should get your first error message:

t/001_about_true_and_false.vim ........ 1/?
not ok 1 - About True and False number 1 is treated as true
# function <SNR>1_main..vspec#test..5, line 1
# Vim(call):E121: Undefined variable: ___
t/001_about_true_and_false.vim ........ Failed 1/6 subtests

The relevant bit is: Undefined variable: ___. To fix it, change the ___ placeholder to the correct answer, in this case:

it 'number 1 is treated as true'
  Expect 'truthy' ==# TruthValue(1)
end

Run the tests again and they should pass.

Move on to the next exercise: delete the line with TODO, then change the ___ placeholder to the correct answer.

About

Teach yourself Vimscript using TDD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published