thoughtbot/vim-rspec — pull request #44 by bolandrm (2014-01-12 06:25:23+00:00)
Title: allow pattern matching of filenames to specs

Hey,

I've added the ability match file name patterns to their associated spec files. For example `app/models/cast.rb` -> `spec/models/cast_spec.rb`. It's kind of like `Guardfile` pattern matching.

First time ever writing vimscript, so let me know if there are any issues.

Anyway, below is the readme section to explain a bit more.

----

The `g:rspec_patterns` variable can be passed a list of lists, which contain
mappings of file names to spec names. The first list element is a regex for
matching the current file's name, and the second element is the spec file
or directory to run.

In this example, we're any time we run `RunCurrentSpecFile()` for a controller
or javascript file, we run the `spec/features` directory. Any time we run the
command in a model file, we run that model's spec.

Notice that the regex group matches from the first parameter can be
interpolated into the second parameter with the syntax `{MATCH#}`, i.e.,
`{MATCH1}` or `{MATCH3}`.

```vim
let g:rspec_patterns = [
\ [ '\v^app/.+_controller\.rb$', "spec/features" ],
\ [ '\v^app/.+(\.js|\.coffee)$', "spec/features" ],
\ [ '\v^app/(.+)\.rb$', "spec/{MATCH1}_spec.rb" ]
\ ]
```